Problems To Upgrade Android Gradle Plugin from 4.1.3 to 8.1.2 and solutions
Upgrade Android Gradle Plugin from 4.1.3 to 8.1.2
Key Challenges
- Installing App in my Device through USB
- Generate Build APK
- Generate Signed Bundle
I faced myriads of problems while upgrading from 4.1.3 to 8.1.2.
(This is my personal diary. But if anyone else finds it helpful, that will be my two cents)
Problem: Updates available
To take advantage of the latest features, improvements and fixes, we recommend that you upgrade this project's Android Gradle Plugin from 4.1.3 to 4.2.2.
Solution: In build.gradle - Project Level
Set classpath "com.android.tools.build:gradle:4.2.2"
See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.
Solution: From StackOverflow
Problem: To take advantage of the latest features, improvements and fixes, we recommend that you upgrade this project's Android Gradle Plugin from 4.2.2 to 7.4.2.
IIn build.gradle - Project Level
Solution: classpath "com.android.tools.build:gradle:7.4.2"
Problem: Minimum supported Gradle version is 7.5. Current version is 7.2.
Please fix the project's Gradle settings.
Solution:
Change Gradle version in Gradle Wrapper to 7.5
My App successfully upgraded. Now Building APK
Problem:
Manifest merger failed with multiple errors, see logs
Execution failed for task ':app:processDebugAndroidTestManifest'.
> Manifest merger failed with multiple errors, see logs
* Try:
>
Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
>
Run with --scan to get full insights.
Problem:
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:processDebugAndroidTestManifest'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:142)
at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:282)
Caused by: java.lang.RuntimeException:
Manifest merger failed with multiple errors, see logs
Probable Solution:
Clean and Rebuild
Problem:
Gradle Daemon Memory Utilization
4.3% (0.5s) of your build’s time was dedicated to garbage collection during this build. You can change the Gradle daemon heap size on the memory settings page.
Edit Memory Settings
Solution: I did nothing and did implement this fix.
Problem: Manifest merger failed with multiple errors, see logs
Problem: Updates available
To take advantage of the latest features, improvements and fixes, we recommend that you upgrade this project's Android Gradle Plugin from 7.4.2 to 8.1.2.
Solution: classpath "com.android.tools.build:gradle:8.1.2"
Problem:
Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.
If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file.
Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.
Solution: From StackOverflow
I have added the following lines to app/build.gradle
android{
namespace 'com.example.application
....
}
Problem:
error: constant expression required
Resource IDs will be non-final by default in Android Gradle Plugin version 8.0, avoid using them in switch case statements case R.id.login
Solution: Removed all Switch-Case construct for menu items to IF-ELSE Block.
Updated all files. App installed in debug. Working fine at 9:12 am
Problem:
Execution failed for task ':app:processDebugAndroidTestManifest'.
> Manifest merger failed with multiple errors, see logs
*
Try:
>
Run with --stacktrace option to get the stack trace.
>
Run with --info or --debug option to get more log output.
PROBLEM: Exported service does not require permission Android Java
Solution: Google
If this receiver handles non-system broadcasts, specify a value for android:exported . Set this value to "true" if you want your receiver to be able to receiver broadcasts from other applications or "false" if you only want your receiver to be able to receive broadcasts from your own app
Problem: Execution failed for task ':app:processDebugAndroidTestManifest'.
> Manifest merger failed with multiple errors, see logs
Run: UpgradeAssisrtant
The upgraded project successfully synced with the IDE. You should test that the upgraded project builds and passes its tests successfully before making further changes.
The upgrade consisted of the following steps:
Migrate DSL properties from lintOptions to lint
Problem: Task :app:processDebugAndroidTestManifest FAILED
/Users/siddharthabhattcharyya/StudioProjects/myandroidapp/app/build/intermediates/tmp/manifest/androidTest/debug/tempFile1ProcessTestManifest16228933121395405637.xml Error:
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 https://developer.android.com/guide/topics/manifest/activity-element#exported for details.
androidx.test:core library version 1.3.0. Upgrading to version 1.4.0 fixed the issue.
I could not find test:core
But I found and updated following plugins
testImplementation 'junit:junit:5'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
Solution Implemented:
Finally, updated all plugin versions to their latest version in build.gradle file (Module App)
All problems solved. Now, APK generation works.
But still there were few problems.
Problem: buildToolsVersion and compileSdkVersion had been deprecated
Solution: StackOverflow
Problem: buildToolsVersion deprecated
Warning from Google PlayConsole
he developer of Google Play Core (com.google.android.play:core)
Change compileSdkVersion to compileSdk
android {
// compileSdkVersion Deprecated for API >= 33
compileSdk 34
// buildToolsVersion "30.0.3"
namespace "in.example.myapp"
.....
Like above
Now, App Bundle was generated.
Tried to publish in Google Play Console.
Got the following warning.
Problem: Your app contains a vulnerability that can lead to an attacker writing data to your app's internal storage. This is because your app is using an old version of the Play Core Library. Update the Play Core Library in your app to the latest version (1.7.2 or above).
SOLUTION: ADDED
implementation 'com.google.android.play:core:1.10.3' TO BUILD.GRADLE (APP LEVEL)
All Problems Solved.
New App Bundle published in Google PlayStore for review.
Hope it gets approved early.
Enjoy Coding. Have a great time.
Comments
Post a Comment