Programming Tips - Android upgrade to API 31 issues.

Date: 2023may1 Q. Android upgrade to API 31 issues. A. Problem: "Could not find" "Could not find" "Could not find" "Could not find" "Could not find" Solution: Just remove: implementation '' implementation '' implementation '' implementation '' implementation '' Problem: android:exported needs to be explicitly specified for element <activity#com.example.myapp.MainActivity>. Solution: Added to AndroidManifest.xml <activity android:exported="true" Problem: Manifest merger failed : android:exported needs to be explicitly specified for element <>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See for details. Solution: Added to manifest: <manifest xmlns:android="" xmlns:tools=""> ... <application> <receiver android:name="" android:enabled="true" android:exported="false" tools:node="merge" tools:overrideLibrary=""> <intent-filter> <action android:name=""/> </intent-filter> </receiver> <application> Problem: Android resource linking failed /layout/content_main.xml:16: error: attribute layout_behavior (aka com.example.myapp:layout_behavior) not found. error: failed linking file resources. Solution: Change app:layout_behavour to app:layout_behavior And ensure you have at the top: xmlns:app="" Problem: package does not exist import; Solution: Change implementation '' to implementation 'androidx.legacy:legacy-support-v4:1.0.0' in build.gradle Or if you're using androidx: implementation '' Problem: Configuration `:app:debugRuntimeClasspath` contains AndroidX dependencies, but the `android.useAndroidX` property is not enabled, which may cause runtime issues. Set `android.useAndroidX=true` in the `` file and retry. Solution: Add android.useAndroidX=true to Problem: Your project has set `android.useAndroidX=true`, but configuration `:app:debugRuntimeClasspath` still contains legacy support libraries, which may cause runtime issues. This behavior will not be allowed in Android Gradle plugin 8.0. Please use only AndroidX dependencies or set `android.enableJetifier=true` in the `` file to migrate your project to AndroidX (see for more info). The following legacy support libraries are detected: Solution: Add android.enableJetifier=true to Problem: ERROR:F:\AndroidStudioProjects\<myproject>\app\src\main\res\layout\content_main.xml:9: AAPT: error: resource string/appbar_scrolling_view_behavior (aka com.hogdex.HashPostFree:string/appbar_scrolling_view_behavior) not found. Solution: Add to build.gradle implementation '' Problem: Need to convert to androidx Solution: Select Menu Refactor > Convert to androidx And make sure to click on [Do Refactor] bottom left. In build.gradle add: dependencies { ... def appcompat_version = "1.3.1" implementation "androidx.appcompat:appcompat:$appcompat_version" // For loading and tinting drawables on older versions of the platform implementation "androidx.appcompat:appcompat-resources:$appcompat_version" } According to Change imports androidx.appcompat.widget.Toolbar androidx.annotation.Nullable androidx.annotation.LayoutRes androidx.coordinatorlayout.widget.CoordinatorLayout In your .java AND your .xml layouts In main layout <androidx.core.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <include layout="@layout/content_main_norm" /> </androidx.core.widget.NestedScrollView> as per