'kotlin-android-extensions' is no longer supported even though not using - android

Since the weekend assembling a release with ./gradlew assembleRelease --stacktrace won't work any longer
We get the following error even though we are not using either 'kotlin-android-extensions' or 'parcelize'
> Task :detox:compileCoreNativeReleaseKotlin FAILED
e: The Android extensions ('kotlin-android-extensions') compiler plugin is no longer supported. Please use kotlin parcelize and view binding. More information: https://goo.gle/kotlin-android-extensions-deprecation

Related

Kotlin module problem that turns into java noClassDefFoundError

When building my project in Android Studio, I get the following error.
Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.16.
I have tried changing the Kotlin version in my project-level gradle file to almost every single stable release available without much success. The one or two stable releases of Kotlin that do make this error go away generate their own errors.
The current Gradle version 5.6.4 is not compatible with the Kotlin Gradle plugin. Please use Gradle 6.1.1 or newer, or the previous version of the Kotlin plugin.
jav.lang.noClassDefFoundError
Build file 'C:\Users\pictu\Downloads\ble-starter-android-master\ble-starter-android-master\app\build.gradle' line: 18
A problem occurred evaluating project ':app'.
> org/gradle/api/services/BuildService
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':app'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$2.run(DefaultScriptPluginFactory.java:227)
at
...
org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:91)
... 130 more
Caused by: java.lang.ClassNotFoundException: org.gradle.api.services.BuildService
... 160 more
I've tried using multiDex, I've tried changing the Kotlin version, I've tried changing the compileSdkVersion + minSdkVersion + targetSdkVersion, but none of them worked. I've also looked at several SO posts, but I haven't found any that help my specific issue.
UPDATE 1: The error message points out this line specifically.
apply plugin: 'kotlin-android'
UPDATE 2: The answer to this SO post helped me get a little further. Now I am getting this cryptic stack trace that mentions something about a circular reference. I haven't been able to find out what a circular reference is in this context.
Invoke-customs are only supported starting with Android O (--min-api 26)
Stack trace:
com.android.tools.r8.a: Invoke-customs are only supported starting with Android O (--min-api 26)
at com.android.tools.r8.dex.r.a(:289)
at com.android.tools.r8.dex.r.a(:98)
at com.android.tools.r8.dex.r.b(:188)
at com.android.tools.r8.dex.b.a(:63)
at
...
Caused by: [CIRCULAR REFERENCE: com.android.tools.r8.a: Invoke-customs are only supported starting with Android O (--min-api 26)]
These are the two Stack Overflow posts that led me to my answer (1, 2).
You need to update your Gradle settings. I updated mine to Gradle version 6.1.1 using the chart in the answer to the first SO post I referenced.
The second thing you need to do is specify sourceCompatibility and targetCompatibility as JavaVersion.VERSION_1_8 in the compileOptions section of the app level Gradle file.

How can my Gradle plugin define a task depending on a task of AGP 7.0.0?

I have written a Gradle plugin based on Android Gradle Plugin: for each variant, the plugin defines a task generatevariantStuff that generates an asset and I need that the mergevariantAssets (defined by AGP) takes my asset as an input, so the mergevariantAssets task must depend on my generatevariantStuff task.
My plugin works properly with AGP 4.2.2.
AGP 7.0.0 deprecates com.android.build.gradle.api.ApplicationVariant and replaces it by com.android.build.api.variant.ApplicationVariant, so that I have to replace also com.android.build.gradle.AppExtension by com.android.build.api.variant.ApplicationAndroidComponentsExtension and the loop on the variants.
Now, when Android Studio builds the model, it fails with the following error:
A problem occurred configuring project ':app'.
> Task with name 'mergeDebugAssets' not found in project ':app'.
But in Gradle view of Android Studio a can see the mergeDebugAssets task.
It seems that during the method AppExtension.getApplicationVariants().all() (AGP 4.2.2), AGP has already defined its tasks, while, during the method ApplicationAndroidComponentsExtension.onVariants() (AGP 7.0.0), AGP has not yet defined its tasks.
You can see sample code at https://gist.github.com/dscoppelletti/d4ca0e1a19ed4ba4aaea99cf48ae930a
Any help is appreciated.
I have similar issues with it. I have an aggregated task that collects artifacts from each variant and copies them to a given path, but assemble tasks for variants are not available during ApplicationAndroidComponentsExtension.onVariants()

How to deal with these deprecation warnings by Gradle v6.3?

I updated Android Gradle Plugin to v3.6.2 and Grade to v6.3 in Android Studio. When I run a build with the compiler option --warning-mode all, I get the following two deprecation warnings:
1:
Configure project :app
Internal API constructor DefaultDomainObjectSet(Class<T>) has been deprecated. This is scheduled to be removed in Gradle 7.0. Please use ObjectFactory.domainObjectSet(Class<T>) instead. See https://docs.gradle.org/6.3/userguide/custom_gradle_types.html#domainobjectset for more details.
at build_gklh609eby8f87cnghyses56.run(E:\Mahalaya\app\build.gradle:1)
(Run with --stacktrace to get the full stack trace of this deprecation warning.)
2:
Querying the mapped value of map(property(interface org.gradle.api.file.Directory, property(interface org.gradle.api.file.Directory, fixed(class org.gradle.api.internal.file.DefaultFilePropertyFactory$FixedDirectory, E:\Mahalaya\app\build\generated\ap_generated_sources\debug\out)))) before task ':app:compileDebugJavaWithJavac' has completed has been deprecated. This will fail with an error in Gradle 7.0. Consult the upgrading guide for further information: https://docs.gradle.org/6.3/userguide/upgrading_version_6.html#querying_a_mapped_output_property_of_a_task_before_the_task_has_completed
It hasn't been a long time since I have started programming in Android, and I have no idea about what to do about these warnings. I can't understand what is being said in the links. Any help is appreciated.
Update: Gradle v6.5 shows the same warnings.
I think it is caused by one of these plugins. I have it too:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
And i also think they will update these plugins as well. So that the deprecation would not be a problem.

Gradle plugin 3.5.0: "Failed to transform artifact", "Execution failed for JetifyTransform"

We updated Android Gradle plugin from 3.4.2 to 3.5.0 (and Gradle from 5.1.1 to 5.4.1).
After that, the build started failing in a few submodules. Trying to assemble any build variant yields this (same error on the command line and in Android Studio):
> Failed to transform artifact 'bottom-navigation.aar (project :bottom-navigation)' to match attributes {artifactType=jar}.
> Execution failed for JetifyTransform: <project_root>/bottom-navigation/build/outputs/aar/bottom-navigation-release.aar.
> Failed to transform '<project_root>/bottom-navigation/build/outputs/aar/bottom-navigation-release.aar' using Jetifier.
Reason: Cannot open a library at 'FileMapping(from=<project_root>/bottom-navigation/build/outputs/aar/bottom-navigation-release.aar, to=<project_root>/bottom-navigation/build/.transforms/9b2af95a5f0e0055110660c22ff05ab5/jetified-bottom-navigation-release.aar)'. (Run with --stacktrace for more details.)
Any ideas how to fix this?
What I've tried
"Invalidate caches" in AS and also clearing all Gradle caches in ~/.gradle/caches as suggested in this answer
All the advice in this somewhat similar question
I checked that the problematic modules use apply plugin:
'com.android.library' (instead of com.android.application)
I tried updating appcompat dependency to androidx.appcompat:appcompat:1.1.0 in affected modules and also removing that dependency
Update
It starts to look like something is wrong in Gradle plugin 3.5.0; builds behave erratically for me locally and on our CI machine.
For example, clean builds are failing: ./gradlew clean assembleBetaRelease fails while ./gradlew assembleBetaRelease works!
Also, sometimes I get AAPT: error: attribute ... not found instead of the above Failed to transform artifact error.
Reverting to Gradle plugin 3.4.2, all these problems disappear.
Edit Oct 2019: Still seeing this weird behaviour with Gradle plugin 3.5.1. Edit Nov 2019 And 3.5.2. Upgrading to Gradle 5.6 didn't help either.
A bit weird, but I got it working again. Apparently just a temporary glitch in Android Gradle plugin related to caching.
This answer helped me:
The simple way to solve this is to switch between your build variants. This refreshes the cached copies and resolves the issue.
I couldn't do that in Android Studio since the project sync was failing, but on the command line I tried another variant (in my case ./gradlew assembleBetaDebug having used ./gradlew assembleBetaRelease earlier). The build passed, and after that it worked for all all other variants too, and Gradle sync in Android Studio started working as well!
Edit: actually this is not completely solved; see updated question.
Update 12/2019: bundle* commands work fine, it's only assemble* that fails—still failing with Android Gradle plugin 3.5.3. Building in Android Studio works fine. Obviously this is not a common issue, and I don't know what exactly in the particular project I'm working on is causing this.
Update 04/2020: now with Android Gradle plugin 3.6.2 (and Gradle 5.6.4) builds work for me locally and I was able to update the project. On CircleCI, the build still occasionally fails with "Failed to transform artifact" but re-running fixes it. Go figure 🤔

Building cordova-plugin-xapkreader with cordova-android 6.4.0

I've inherited a cordova project that uses cordova-plugin-xapkreader, which appears to be the standard plugin for accessing expansion (aka OBB) files. I'm encountering an issue with it that I would expect to affect other cordova plugins. I get the following errors when running cordova build android:
Configuration 'compile' in project ':' is deprecated. Use 'implementation' instead.
publishNonDefault is deprecated and has no effect anymore. All variants are now published.
Configuration 'compile' in project ':com.flyingsoftgames.xapkreader:downloader_library' is deprecated. Use 'implementation' instead.
publishNonDefault is deprecated and has no effect anymore. All variants are now published.
Configuration 'debugCompile' in project ':com.flyingsoftgames.xapkreader:downloader_library' is deprecated. Use 'debugImplementation' instead.
Configuration 'releaseCompile' in project ':com.flyingsoftgames.xapkreader:downloader_library' is deprecated. Use 'releaseImplementation' instead.
Configuration 'compile' in project ':com.flyingsoftgames.xapkreader:library' is deprecated. Use 'implementation' instead.
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':debugCompileClasspath'.
> Could not resolve project :com.flyingsoftgames.xapkreader:library.
Required by:
project : > project :com.flyingsoftgames.xapkreader:downloader_library
> Project :com.flyingsoftgames.xapkreader:downloader_library declares a dependency from configuration 'debugCompile' to configuration 'debug' which is not declared in the descriptor for project :com.flyingsoftgames.xapkreader:library.
This has been reported as a bug on the plugin's forum by someone else, but the workaround doesn't reliable work:
https://github.com/agamemnus/cordova-plugin-xapkreader/issues/116
The issue appears to be that gradle expects you to now use implementation rather than compile, debugCompile etc. The gradle file for the plugin is generated by cordova, based on a template inside cordova-android. The suggested workaround is to modify the template (or the generated gradle files) in a script run from a cordova hook. Unfortunately for some reason, the hooks don't appear to work reliably - sometimes they do, sometimes they don't. This feels like it may be due to a race condition caused by the hooks running asynchronously with the rest of the build process - so sometimes the gradle build has started before the gradle files can be modified.
Does any have any ideas how to properly fix this? Does anyone know why this isn't a more wide-spread issue that the cordova-android project hasn't fixed by modifying their template? Is this something I can fix by downgrading some part of the build process?
I'm pretty new to Cordova, so it's all quite baffling and any help is much appreciated!
Unfortunately for some reason, the hooks don't appear to work reliably
- sometimes they do, sometimes they don't. This feels like it may be due to a race condition caused by the hooks running asynchronously
with the rest of the build process - so sometimes the gradle build has
started before the gradle files can be modified.
I think this can be fixed by making the hook return a promise, this way you can ensure the rest of the build won't run in parallel. I posted the code I'm using on the github issue.
The revelant code is the following:
- create a promise at the beginning of the hook:
const deferral = context.requireCordovaModule('q').defer();
- return the promise at the end of the hook:
return deferral.promise;
- resolve the promise once the work is finished (the file is written):
deferral.resolve();

Categories

Resources