Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Android-Support to AndroidX Upgrade#1856

Merged
spyhunter99 merged 7 commits intoosmdroid:masterfrom
ScriptTactics:feature/#1453
Nov 25, 2022
Merged

Android-Support to AndroidX Upgrade#1856
spyhunter99 merged 7 commits intoosmdroid:masterfrom
ScriptTactics:feature/#1453

Conversation

@PWRxPSYCHO
Copy link
Copy Markdown
Contributor

@PWRxPSYCHO PWRxPSYCHO commented Oct 13, 2022

After looking into upgrading NGA-Geopackage, it seems that there are too many clashing dependencies from android.support and androidx. I saw there was a feature request to update the older libraries to the newer libraries.

PR: #1853 - should be done after this to resolve the duplicate file issues

Issue: #1453

I followed this guide: https://developer.android.com/jetpack/androidx/migrate/artifact-mappings to update all legacy mappings to the equivalent AndroidX

@PWRxPSYCHO
Copy link
Copy Markdown
Contributor Author

@PWRxPSYCHO
Copy link
Copy Markdown
Contributor Author

PWRxPSYCHO commented Oct 14, 2022

https://github.com/osmdroid/osmdroid/actions/runs/3245835164/jobs/5328503169#step:5:1338

I will investigate this unit test error.

It looks like all the tests are passing. There is one test skipped in the WMS parser but that module is still in beta so I don't see an issue with it skipping.

https://github.com/osmdroid/osmdroid/actions/runs/3245835164/jobs/5328503169#step:5:1345

Says to look at file:///Users/runner/work/osmdroid/osmdroid/osmdroid-android/build/reports/tests/testDebugUnitTest/index.html
Which is this:
osmdroid-android
Screenshot 2022-10-14 at 08-58-16 Test results - Test Summary
it doesn't look like its actually failing

osmdroid-wms
Screenshot 2022-10-14 at 08-58-47 Test results - Test Summary

osmdroid-shape
Screenshot 2022-10-14 at 08-58-34 Test results - Test Summary

@PWRxPSYCHO PWRxPSYCHO changed the title Updated from android-support to androidx Android-Support to AndroidX Upgrade Oct 14, 2022
@PWRxPSYCHO
Copy link
Copy Markdown
Contributor Author

@spyhunter99 @MKergall @neilboyd @kurtzmarc @monsieurtanuki @eclectice - I was looking to try and setup a discussion about this PR or at least get some information on the path forward with this in relation to the project. If these changes are already planned for the next release of OSMDroid we can delete this PR and hold off with the NGAGeopackage PR until the AndroidX upgrade has been completed.

The Meshtastic Android App just recently started to use OSMDroid as their main mapping tool and this PR would help solve loading external map files.

Thank you for your work on this awesome project and contributions to the open source community. 😄

Copy link
Copy Markdown
Collaborator

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @PWRxPSYCHO!
From what I read, this PR looks good to me.
The thing is that I have no idea what the impact of that migration would be on legacy apps.
I assume that in 2022 that should be OK, as long as the min sdk is not changed.

@PWRxPSYCHO
Copy link
Copy Markdown
Contributor Author

Hi @PWRxPSYCHO! From what I read, this PR looks good to me. The thing is that I have no idea what the impact of that migration would be on legacy apps. I assume that in 2022 that should be OK, as long as the min sdk is not changed.

@monsieurtanuki I did my best to maintain legacy mappings so they should be 1-1 and cause no breaking changes as far as legacy apps are concerned. The min sdk has not been touched. I did go through all the versions of the dependencies to make sure everything was still compatible.

@eclectice
Copy link
Copy Markdown

eclectice commented Nov 25, 2022

What is the status of this pull request, and when will it be merged into the master branch? I'd like to write a simple app in Kotlin that makes use of ViewPager2.

Only the osmdroid:master branch (6.1.15?) has been tested with the Android Gradle plugin (AGP) 7.5.1, which requires a Java 11 JVM, and it works flawlessly. The broken Simple Map app in this OsmDroid project continues to puzzle me; I remain of the opinion that having the OpenStreetMapViewer app built is adequate.

2022-11-25 09:46:13.030 AndroidRuntime           E  FATAL EXCEPTION: main
                                                    Process: org.osmdroid.osmdroid.simple.map, PID: 17486
                                                    java.lang.RuntimeException: Unable to start activity ComponentInfo{org.osmdroid.osmdroid.simple.map/org.osmdroid.sample.MapActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                    	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
                                                    	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
                                                    	at android.app.ActivityThread.-wrap14(ActivityThread.java)
                                                    	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
                                                    	at android.os.Handler.dispatchMessage(Handler.java:102)
                                                    	at android.os.Looper.loop(Looper.java:154)
                                                    	at android.app.ActivityThread.main(ActivityThread.java:6682)
                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                    	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
                                                    Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
                                                    	at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:852)
                                                    	at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:815)
                                                    	at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:703)
                                                    	at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
                                                    	at org.osmdroid.sample.MapActivity.onCreate(MapActivity.java:28)

To resolve the bug, I changed:

activity_main.xml (osmdroid-simple-map)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical" >
  <androidx.appcompat.widget.Toolbar
      android:id="@+id/my_toolbar"
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
      style="@style/ToolbarStyle"/>
  <org.osmdroid.views.MapView android:id="@+id/mapView"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/>
</LinearLayout>

AndroidManifest.xml (osmdroid-simple-map)

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="org.osmdroid.simplemap">

    <!-- PROTECTION_NORMAL permissions, automatically granted -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />

    <!-- DANGEROUS PERMISSIONS, must request -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
        android:theme="@style/AppTheme"
        android:allowBackup="false"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        tools:ignore="GoogleAppIndexingWarning">
        <activity android:name="org.osmdroid.sample.MapActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        </activity>
    </application>
</manifest>

MapActivity.java (osmdroid-simple-map)

public class MapActivity extends AppCompatActivity {
    private MapView mapView = null;

    @Override
    public void onCreate(Bundle savedInstance) {
        super.onCreate(savedInstance);
        Configuration.getInstance().load(getApplicationContext(),
                PreferenceManager.getDefaultSharedPreferences(getApplicationContext()));
        //TODO check permissions
        setContentView(R.layout.activity_main);
        mapView = findViewById(R.id.mapView);
        androidx.appcompat.widget.Toolbar myToolbar = findViewById(R.id.my_toolbar);
        setSupportActionBar(myToolbar);
    }
   //...
}

These modifications are compatible with both Android 7.0 and Android 11. I don't have a device running Android 13 to test.

On the other hand, did you encounter any prepareKotlinBuildScriptModel error when building OpenStreetMapViewer taken from osmdroid:master branch with Android Studio (Android Studio Dolphin | 2021.3.1 | Build #AI-213.7172.25.2113.9014738)?

Task 'prepareKotlinBuildScriptModel' not found in project ':OpenStreetMapViewer'

To remove the error, I need to include this Gradle groovy snippet in OpenStreetMapViewer's build.gradle:

tasks.register("prepareKotlinBuildScriptModel"){}

@monsieurtanuki
Copy link
Copy Markdown
Collaborator

@spyhunter99 It's probably time to grant merge or/and admin privileges (whatever they're called in github) to contributors that have skills, time and motivation, like @eclectice.

@spyhunter99
Copy link
Copy Markdown
Collaborator

invite sent

@spyhunter99 spyhunter99 merged commit 713f680 into osmdroid:master Nov 25, 2022
@PWRxPSYCHO PWRxPSYCHO deleted the feature/#1453 branch November 25, 2022 15:10
@eclectice
Copy link
Copy Markdown

eclectice commented Dec 1, 2022

@spyhunter99 It's probably time to grant merge or/and admin privileges (whatever they're called in github) to contributors that have skills, time and motivation, like @eclectice.

invite sent

Thank you for the invitation, but I will KIV it for the time being because I am still unfamiliar with git and the GitHub versioning system; I am more familiar with the Subversion system.

@spyhunter99 I pulled your merge, but when I tested it on a physical Android 11 device, it had a lot of issues (specifically Samsung Galaxy Tab S7 FE SM-T733). Even for simple things like accessing shared preferences, getting a system service context, calling Toast.makeText(), and so on, the OpenStreetMapViewer app receives a lot of StrictMode disk read/write violations. To reduce them, I use StrictMode.allowThreadDiskWrites() whenever possible.

        StrictMode.ThreadPolicy oldPolicy = null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
            oldPolicy = StrictMode.allowThreadDiskWrites();
        }
        try {
            mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
        } finally {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
                StrictMode.setThreadPolicy(oldPolicy);
            }
        }

I'm also implementing various permission checks for code that requires runtime permissions. Because there are cleartext network traffic errors when accessing some OpenStreetMap links, I'm adding them to the app's network configuration file.

My work is still in progress. I will keep you informed when it is done.

@eclectice
Copy link
Copy Markdown

eclectice commented Dec 8, 2022

When running any sample demo that uses the GpsMyLocationProvider on an Android 11 device, it appears that the sample demo receives a leak notification from Leak Canary. Following further investigation, it appears that the Location Service obtains its context from the activity rather than the application context. This is well explained in this article: https://dev.to/pyricau/beware-packagemanager-leaks-223g.

As a result, I changed the majority of the system services in the sample demos to use the application context rather than the activity context, with the exception of Context.LAYOUT_INFLATER_SERVICE, which requires the activity context. However, I skipped the sample demos in the Bug Drivers section.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants