'Failed to transform" error after migrating to AndroidX - android

I'm using Android Studio 3.2 Canary 14 and am trying to migrate an existing project to use AndroidX. It sounds from https://developer.android.com/topic/libraries/support-library/androidx-rn that I have to have set android.enableJetifier=true (this was done automatically for me when selecting "Refactor to AndroidX.." option). I've also updated target API level to 28. Anyone else seeing this issue?
Failed to transform
'/Users/jooreill/.gradle/caches/modules-2/files-2.1/com.google.firebase/firebase-perf/15.0.0/6e68f6e44b0c9d91756f903547ee3853349ae666/firebase-perf-15.0.0.aar' using Jetifier. Reason: null. (Run with --stacktrace for more
details.) To disable Jetifier, set android.enableJetifier=false in
your gradle.properties file.
The above error occurs when I run "Clean". In general am getting multiple errors like following if a do gradle sync:
Unable to resolve dependency for
':app-instant#debug/compileClasspath': Failed to transform file
'play-services-measurement-base-15.0.2.aar' to match attributes
{artifactType=jetified-aar} using transform JetifyTransform

For those experiencing the same issue with Android Studio 3.2 Canary 15 (or later) after using "Refactor to AndroidX...":
I had to update some dependencies manually, i.e. change
classpath 'io.fabric.tools:gradle:1.25.1'
to
classpath 'io.fabric.tools:gradle:1.27.0'
in my project's build.gradle file.
If you're using dagger you have to upgrade to version 2.20 or later.
This is because some libraries are not yet compatible with the AndroidX refactor as mentioned under Known issues in the AndroidX release notes.

I had been experiencing this problem while running assembleAndroidTest on Jenkins.
The weirdest part was that this task ran sans any issues on my mac's terminal without any issues, but failed on Jenkins with-
Failed to transform file 'cucumber-java-1.2.5.jar' to match attributes {artifactType=processed-jar} using transform JetifyTransform
Had been looking for solutions for a couple of days now, having worked though different suggestions - none of which worked.
Finally, disabling Jetifier in gradle.properties resolved it for me.
android.enableJetifier=false

I was able to work around a similar problem by excluding a certain library from being jetified, which can be done by adding to gradle.properties:
android.jetifier.blacklist = ...
Note that this option was added in Android Gradle plugin 3.3.0-rc01 as a temporary workaround.
See https://issuetracker.google.com/issues/119135578#comment5 for more details.

As per a statement on the AndroidX refactor made by a Google Engineer (Support Library) during the I/O session "What's New in Support Library?", Google already discovered bugs related to Jetifier in Android Studio 3.2 Canary 14.
Thus, it is advised to wait until Canary 15 (to be released the coming week) before starting the AndroidX migration process.

I had this same error after adding JDK 11 to my machine. It set itself as default JDK and this error started happening.
After setting JDK 8 as default, it was fixed.

Related

A problem occurred configuring project ':#react-native-async-storage_async-storage'

I get this error when I try to run react-native run-android.
This is the full error message:
A problem occurred configuring project ':#react-native-async-storage_async-storage'.
com.android.builder.errors.EvalIssueException: defaultConfig contains custom BuildConfig fields, but the feature is disabled.
To enable the feature, add the following to your module-level build.gradle:
android.buildFeatures.buildConfig true
I've found these solutions to similar errors: this, this, this and this but, the problem still remains.
In other words,
I updated my java version to 15 (I tried also 19).
I tried different Gradle Versions (mainly of 8+).
I installed npm i jetifier.
I added android.buildFeatures.buildConfig true in android/app/build.gradle (ChatGPT suggestion).
There is also a suggestion to the issue I've opened here
I updated Android Studio
Additional notes:
The app is uploaded in Play Store and the last time I worked on it, was three months ago. So I guess I have to update something.
I used to have the community package #react-native-community/async-storage, which is deprecated, so I replaced it with this one: #react-native-async-storage/async-storage.

How can I fix "unexpected element <queries> found in <manifest>" error?

All of a sudden, I am getting this build error in my Android project:
unexpected element <queries> found in <manifest>
How do I fix it?
The Android Gradle Plugin needs to know about new manifest elements, particularly
for the manifest merger process. The plugin has a tendency to get confused if it
sees elements in the manifest merger that it does not recognize, tossing out
build errors like the one in the question.
In this case, Android 11 introduced <queries> as a manifest element, and older versions of the Android Gradle Plugin do not know about that element.
The fact that this occurs from manifest merger means that simply upgrading a dependency
might bring about this error. For example, if you upgrade to the latest
version of com.awesome:awesome-library, and it contained a <queries> element
in its manifest, you might crash with the aforementioned error in your builds,
even without any other changes in your code.
Google released a series of patch versions of the Android Gradle Plugin to address this:
3.3.3
3.4.3
3.5.4
3.6.4
4.0.1
If you are using an existing plugin in the 3.3.* through 4.0.* series, upgrade
to the associated patch version (or higher) from that list, and you should no longer
run into that error (e.g., classpath 'com.android.tools.build:gradle:4.0.1').
If you are using Android Studio 4.1 or higher, with a matching
Android Gradle Plugin (e.g., in the 4.1.* series), you should be fine without
any changes. Those plugin versions were already aware of <queries>.
See this Android Developers Blog post for more.
I had this issue in Flutter, but I believe this solution will work for both Flutter and native Flutter development.
Follow these steps
Read this short blog post to get some understanding: Preparing your Gradle build for package visibility in Android 11
Delete the .gradle folder inside the Android folder, i.e., android > .gradle
In the project build.gradle file, upgrade your class path appropriately based on the blog in the link above, e.g., I upgraded to classpath 'com.android.tools.build:gradle:4.0.1'
Upgrade the distribution URL too. It's in android>gradle>gradle-wrapper.properties file appropriately. E.g., I upgraded it to distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
You can invalidate caches and restart your Android Studio. Make sure you have a good Internet connection, because it will download the new Gradle files.
I also suddenly had the same issue two days ago in Android Studio 4.1.1. I solved the issue by upgrading the build Gradle version.
Previous setting in the build.gradle file of the project was:
classpath("com.android.tools.build:gradle:3.5.3")
Current setting:
classpath("com.android.tools.build:gradle:3.5.4")
The issue was gone immediately. :)
Fixing the error is very simple.
Update your Android Studio to the last version
and use the last stable Gradle plugin version.
At the current time, I use Android Studio version 4.1.3 with Gradle Plugin 6.8.2
For use in queries, you should write queries code in out of application tag, not inside application tag.
For more information, see the photo below:
I had this error in the react-native-image-crop-picker library, and I solved this problem by updating the Gradle version as mentioned in previous answers.
It was:
classpath("com.android.tools.build:gradle:3.5.3")
Updated to:
classpath("com.android.tools.build:gradle:3.5.4")
And I ran a:
cd android && ./gradlew clean && cd .. && npx react-native run-android
Then it worked OK.
Due to the new default settings and features for package visibility in Android 11 that need to add <queries>, you must update your Android Gradle plugin.
Google has added some patches to current versions listed in Android Gradle plugin release notes, 4.0.0 (April 2020).
If you want to use a newer version of Android Gradle, you should search for a compatible wrapper from Android Gradle plugin release notes, Update Gradle.
Update your Gradle version to 4.0.1 or later.
File android/gradle/wrapper/gradle-wrapper.properties: update the distribution URL to:
distributionUrl=https://services.gradle.org/distributions/gradle-6.7-all.zip
File android/build.gradle: update the Gradle plugin:
classpath 'com.android.tools.build:gradle:4.1.2'
to 4.0.1 or later. Here it is 4.1.2 with Gradle version to 6.5 or later.
You can see the distribution chart at How to update gradle in android studio?

Firebase performance monitor causing "D8: Unsupported source file type"

I added
apply plugin: 'com.google.firebase.firebase-perf'
and when I ran build script I got
/transforms/FirebasePerformancePlugin/dev/debug/174/module-info.class:
D8: Unsupported source file type
What kind of problem it could be?
I updated all plugins, play services, and Android Studio, but with no luck
I Solve This issue by updating gradle version
classpath 'com.android.tools.build:gradle:3.5.3'
Update: Android Gradle Plugin 3.5.0 fixes this. See this issue and this one issue, both fixed.
(Unfortunately, in my project, this other issue still remains even in 3.5.3.)
I started getting the same error after updating a (company internal) library dependency, but then I kept getting it even after reverting that update. Very strange!
> Task :app:transformClassesAndResourcesWithR8ForBetaRelease FAILED
R8 is the new Android code shrinker. If you experience any issues, please file a bug at
https://issuetracker.google.com, using 'Shrinker (R8)' as component name. You can
disable R8 by updating gradle.properties with 'android.enableR8=false'.
.../transforms/FirebasePerformancePlugin/beta/release/66/module-info.class:
D8: Unsupported source file type
The only thing I found that helped was to do what the Gradle build output says and temporarily switch back to ProGuard, with:
android.enableR8=false
in gradle.properties.
This issue was fixed somewhere between Android Studio 3.5 Beta 2 and Android Studio 3.6 Canary 5, there were a bunch of similar issues with module-info.class.
In my case to fix issue I had not only update Android Studio, but also update gradle plugin.
Steps is:
Install new version alongside your stable version (You also can configure current version to use updates from canary chanel)
More info here
Download link (I downloaded 3.6 Canary 5)
After you installed new Android Studio update grade plugin:
in
gradle/wrapper/gradle-wrapper.properties
chande distributionUrl to
distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip
Don't forget Build->Clean Project
Turn off Firebase-performance plugin.
Android Studio 3.6 Canary 1 has this issue too.
I didn't find another way to release build my project.
i solve this problem with 3 steps:
1.update the "distributionUrl=https://services.gradle.org/distributions/gradle-5.6.4-all.zip"
2.update the "classpath "com.android.tools.build:gradle:3.6.3"
3.update the Studio 3.6.3
in other way(i don't like it)
//apply plugin: 'com.google.firebase.firebase-perf'
...
//classpath "com.google.firebase:perf-plugin:1.3.1"

Meaning of "android.enableAapt2 will be removed at the end of 2018"?

Gradle version: 4.4
Android Plugin Version: 3.1.2
Hi.
I'm working on an Android which should be deploy by using a Mobile Device Management called AirWatch.
So since Android Gradle Plugin 3.0.0, even if I update application version code and version name, the MDM thinks that the last deployed version and the current one are the same.
Using dump badging command, I see that the platformBuildVersionName is empty. So when I disable aapt2 from my gradle properties file, platformBuildVersionName is filled. which allow me to deploy on the MDM. The problem is not up to date we don't when they will. So this is the work around I found. I know that the option 'android.enableAapt2' is deprecated and should not be used anymore.
My question is what's the meaning "It will be removed at the end of 2018"? Is that mean, at the end of 2018, my app will not compile anymore?
Thanks
The issue with platformBuildVersionName missing has been fixed recently in AAPT2.
AAPT2 it is now released it in GMaven for faster releases (so you need to have the google() dependency in your build.gradle file), so please try with android gradle plugin 3.2.0 alpha16 or newer which may already contain it. If that still doesn't work, keep an eye out for new versions, it should be released shortly (if it hasn't been yet).
As for the information about AAPT1 deprecation - it means that at some point in the near future, near the end of 2018, there will be a release of Android Gradle Plugin that removes the android.enableAapt2=false flag. AAPT1 will be completely removed then so the hacks with disabling AAPT2 won't work anymore. If you run into any other issues with AAPT2 please file them on issue tracker, so that the team can fix them before everyone will need to move away from AAPT1.
In 2019 New update
From Gradle.properties remove
android.enableAapt2=false this line
it will work now.
1.Projenin gradle.properties:
android.enableAapt2=false
2.File-> settings-Build, Execution > Instant run
unselected all options and rebuild projects

Could not create an instance of Tooling API implementation using the specified Gradle installation

I just downloaded and installed the latest version of android studio (v 1.4). After creating a new project, I see this error about the gradle refresh failure:
Error: Could not create an instance of Tooling API implementation using the specified Gradle installation '/Applications/Android Studio.app/Contents/gradle/gradle-2.4'.
I've tried so many different things that I have found online and no fix. When I open the layout window of the project it says "Gradle project sync failed..."
I am not sure what the error means at all and also do not know how to use any other different version of it.
I had this problem, fix is don't use gradle 2.4 I deleted gradle/gradle 2.4 folder and in gradle/wrapper/ gradle-wrapper-properties in build directory change 'distributionUrl' to another gradle distribution.
Deleting everything in /Library/Java/Extensions/ fixed this for me.
Issue with more info: https://issues.gradle.org/browse/GRADLE-1451
Add lines at the end of eclipse.ini
--illegal-access=warn
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.base/java.util=ALL-UNNAMED
source

Categories

Resources