androidX jetifier - Is there a way to ignore jetifying a .JAR? - android

Trying to update my app to androidX dependencies. Followed instructions here, and compilation failed.
The error came from JetifyTransform task failing to process a certain .JAR dependency (FYI - Samsungs Spass SDK) :
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:kaptGenerateStubsStandardNo_vendorDebugKotlin'.
> Could not resolve all artifacts for configuration ':app:standardNo_vendorDebugCompileClasspath'.
> Failed to transform file 'pass-v1.2.2.jar' to match attributes {artifactType=processed-jar} using transform JetifyTransform
> Failed to transform '/Users/hanandann/StudioProjects/ArnakPaymentsAndroid/Payments/app/libs/pass-v1.2.2.jar' using Jetifier. Reason: null. (Run with --stacktrace for more details.)
> Failed to transform file 'pass-v1.2.2.jar' to match attributes {artifactType=processed-jar} using transform JetifyTransform
> Failed to transform '/Users/hanandann/StudioProjects/ArnakPaymentsAndroid/Payments/app/libs/pass-v1.2.2.jar' using Jetifier. Reason: null. (Run with --stacktrace for more details.)
Trying to jetify with jetifier-standalone tool had similar results:
Hanans-MacBook-Pro:bin hanandann$ ./jetifier-standalone -i /Users/hanandann/StudioProjects/.../app/libs/pass-v1.2.2.jar -o /Users/hanandann/StudioProjects/.../app/libs/pass-v1.2.2jet.jar
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8
at org.objectweb.asm.ClassReader.readFrameType(ClassReader.java:2313)
at org.objectweb.asm.ClassReader.readFrame(ClassReader.java:2269)
at org.objectweb.asm.ClassReader.readCode(ClassReader.java:1448)
at org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1126)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:698)
at org.objectweb.asm.ClassReader.accept(ClassReader.java:500)
at com.android.tools.build.jetifier.processor.transform.bytecode.ByteCodeTransformer.runTransform(ByteCodeTransformer.kt:39)
at com.android.tools.build.jetifier.processor.Processor.visit(Processor.kt:443)
at com.android.tools.build.jetifier.processor.archive.ArchiveFile.accept(ArchiveFile.kt:49)
at com.android.tools.build.jetifier.processor.Processor.visit(Processor.kt:425)
at com.android.tools.build.jetifier.processor.archive.Archive.accept(Archive.kt:76)
at com.android.tools.build.jetifier.processor.Processor.transformLibrary(Processor.kt:421)
at com.android.tools.build.jetifier.processor.Processor.transform(Processor.kt:247)
at com.android.tools.build.jetifier.processor.Processor.transform$default(Processor.kt:234)
at com.android.tools.build.jetifier.standalone.Main.run(Main.kt:157)
at com.android.tools.build.jetifier.standalone.Main$Companion.main(Main.kt:109)
at com.android.tools.build.jetifier.standalone.Main.main(Main.kt)
Now, I don't really mind if SDK's don't get jetified, so I tried setting android.enableJetifier=false in my gradle.properties file, but compilation failed again for a different reason- SupportMapFragment isn't compatible with androidX yet as is reported here
So I'm stuck. With jetify the .JAR won't transform. with it - SupportMapFarg is incompatible.
Any suggestions?
P.S. you know what would be nice? if there was an ignore option for the jetifying function

added this to gradle.properties:
android.jetifier.blacklist = pass
as suggested by folks at google here.
Be warned - this feature is experimental and unsupported.
Update- current syntax is android.jetifier.ignorelist={your.ignored.lib} as Suggested by #YaMiN

Currently android.jetifier.blacklist is deprecated.
It was removed in version 7.0 of the Android Gradle plugin.
This property has been replaced by android.jetifier.ignorelist

If you need to ignore just a specific .jar file from the jetifier. You can add the file name in the gradle.properties like on the last line from this example.
android.useAndroidX=true
android.enableJetifier=true
android.jetifier.blacklist=liblinphone-4.0.1-debug-symbols.jar

Add this in project's gradle.properties:
android.jetifier.blacklist =xx.aar,yy.jar
split the black list with comma
update on 2022/06/07
If you use gradle 7, it change to android.jetifier.ignorelist

Related

Failed build React Native app:mergeDexRelease

Debug version is compiling just fine, however release fails on task app:mergeDexRelease.
I tried so far excluding group in gradle, but without success.
I checked also this Failed to build a React Native signed release but there is no direct answer to how to solve the problem.
I cleaned gradle cache, build folder, removed node_modules and yarn.lock and reinstaled everything
I tried to restart pc
The same error appears for 3 packages: react-native-screens, react-native-safe-area-context, react-native-gesture-handler
Caused by: com.android.tools.r8.internal.a: Type com.facebook.react.viewmanagers.RNGestureHandlerButtonManagerDelegate is defined multiple times: /Users/user/Projects/app/android/app/build/intermediates/project_dex_archive/release/out/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.dex, /Users/user/Projects/app/node_modules/react-native-gesture-handler/android/build/.transforms/8bd7a67ad8066031ac26f199a2fda1a8/transformed/classes/classes.dex
at com.android.tools.r8.internal.tQ.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:14)
at com.android.tools.r8.internal.tQ.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:22)
at com.android.tools.r8.internal.xK.b(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:7)
at com.android.tools.r8.internal.xK.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:23)
at com.android.tools.r8.internal.xK.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:10)
at java.base/java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:2048)
at com.android.tools.r8.internal.xK.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:6)
at com.android.tools.r8.graph.z2$a.e(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:4)
at com.android.tools.r8.dex.b.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:105)
at com.android.tools.r8.dex.b.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:28)
at com.android.tools.r8.D8.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:26)
at com.android.tools.r8.D8.d(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:593)
at com.android.tools.r8.D8.b(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:1)
at com.android.tools.r8.internal.ci.a(R8_3.2.47_ebadcf1df6fbed6005a238b8399b2cd411e753b60758261060e399f9498872a5:24)
... 36 more ```
Answering to myself, the key was to remove
apply plugin: "com.facebook.react"
from app/build gradle.
I also removed react {} block from app/build.gradle.
Can be closed.
As the error indicate, then the class com.facebook.react.viewmanagers.RNGestureHandlerButtonManagerDelegate is defined multiple times. From what I can see it is defined both in the app itself (/Users/user/Projects/app/android/app/build/intermediates/project_dex_archive/release/out/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.dex) and in a module (/Users/user/Projects/app/node_modules/react-native-gesture-handler/android/build/.transforms/8bd7a67ad8066031ac26f199a2fda1a8/transformed/classes/classes.dex). You will have to ensure that there are not two definitions.
The reason this works in debug mode is that the build of the app does not do a full merge of the DEX flies, but just copies in a number of DEX files into the debug APK.
For D8/R8 reference the retrced stacktrace is
Caused by: com.android.tools.r8.utils.AbortException: Type com.facebook.react.viewmanagers.RNGestureHandlerButtonManagerDelegate is defined multiple times: /Users/user/Projects/app/android/app/build/intermediates/project_dex_archive/release/out/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.dex, /Users/user/Projects/app/node_modules/react-native-gesture-handler/android/build/.transforms/8bd7a67ad8066031ac26f199a2fda1a8/transformed/classes/classes.dex
at com.android.tools.r8.utils.Reporter.handleDiagnostic(Reporter.java:81)
at com.android.tools.r8.utils.Reporter.fatalError(Reporter.java:127)
at com.android.tools.r8.utils.ProgramClassCollection.reportDuplicateTypes(ProgramClassCollection.java:74)
at com.android.tools.r8.utils.ProgramClassCollection.lambda$defaultConflictResolver$1(ProgramClassCollection.java:68)
at com.android.tools.r8.utils.ProgramClassCollection.lambda$create$0(ProgramClassCollection.java:28)
at java.base/java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:2048)
at com.android.tools.r8.utils.ProgramClassCollection.create(ProgramClassCollection.java:27)
at com.android.tools.r8.graph.LazyLoadedDexApplication$Builder.build(LazyLoadedDexApplication.java:266)
at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:184)
at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:134)
at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:104)
at com.android.tools.r8.D8.readApp(D8.java:177)
at com.android.tools.r8.D8.run(D8.java:201)
at com.android.tools.r8.D8.lambda$run$1(D8.java:126)
at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:80)

Conflict with Huawei HMS plugin in android with gradle 7.0.0

I'm getting this error with Gradle 7.0 while it was working fine for 6.8.3
agcp-gradle-7-error
AGCPlugin
FAILURE: Build failed with an exception.
What went wrong:
A problem was found with the configuration of task ':app:processDebugAGCPlugin' (type 'AGCPluginTask').
Type 'AGCPluginTask' property 'randomEncryptComponent' of type boolean shouldn't be annotated with #Optional.
Reason: Properties of primitive type cannot be optional.
Possible solutions:
Remove the #Optional annotation.
Use the java.lang.Boolean type instead.
Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#cannot_use_optional_on_primitive_types for more details about this problem.
I no longer get any errors with:
classpath 'com.huawei.agconnect:agcp:1.5.2.300'
and
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
Currently Gradle 7.0 is not supported. As I hear, it will be supported at the end of June.

Android Detekt Build failed

I tried to generate code report using detekt and when execute the below command in terminal
gradle detekt
it showing build failed with below message.
* What went wrong:
Execution failed for task ':app:detekt'.
> Build failed with 395 weighted issues.
As others have said in the comments, this means you have 395 issues in your code (kind of like lint warnings).
Detekt has a maxissues: property that determines whether or not to fail the build if your issues surpass the allowed number of maxissues. What I did was search the whole project for maxissues, which will take you to your detekt-config.yml or default-detekt-config.yml. There, you can change your maxissues to whatever you want.
In our old code base, we had 900 some issues, so I changed mine from maxissues:0 to masissues:1000. As we clean up the code, I hope to bring that number down.

Flutter Image Picker package is not working

I am using image_picker 0.5.2 package for uploading a picture, after I added that dependency into the project I am unable to build my project, getting an exception which is mentioned below. Please help me out.
D8: Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/2.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/3.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/4.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/5.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/6.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/7.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/8.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/9.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/10.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/11.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/12.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/13.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/14.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/15.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/16.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/17.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/18.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/19.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/20.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/21.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/22.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/23.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/24.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/25.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/26.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/27.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/28.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/29.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/30.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/31.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/32.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/33.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/34.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/35.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/36.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/37.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/38.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/39.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/40.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/41.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/42.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/43.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/44.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/45.jar, /Users/harshavardhan/Workspace/cargill_flutter/build/app/intermediates/transforms/dexBuilder/debug/46.jar
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver
* 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.
* Get more help at https://help.gradle.org
BUILD FAILED in 22s
*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
*******************************************************************************************
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
As mentioned in your trace, this error is because of AndroidX incompatibilities in your app. The image_picker plugin migrated to the latest AndroidX support libraries from version 0.5.0.
For your app to work, you can either migrate your app to AndroidX, or if your app depends on any other package which has not been migrated to AndroidX yet, you can lock your image_picker plugin version to 0.4.12+1, which uses the older support libraries.
Add this to your pubspec.yaml to use specific version of this plugin -
image_picker: 0.4.12+1
More about this here.
UPDATE
You can check this answer for an explanation about why migrate to AndroidX. Also, this official blog explains everything regarding AndroidX.
Hope this helps!
You need to migrate to AndroidX for that particular version of the library to work.
Follow the steps in this link to go ahead with the migration.
File _image;
final images=ImagePicker();
Future getImage()async {
var Image=await images.getImage(source: ImageSource.camera);
setState(() {
_image=File(Image.path);
}); }
and when you want to Use the
_image which stored the image path:
Container(
height: 180,
width: 180,
child: ClipRRect(child: _image==null?Center(child: Text('Please Upload a pic'),):Image.file(_image,fit: BoxFit.fill,),),
when you initially run the program the _image variable is not containing the image path actually the path is empty or null and the error appears so do
_image==null?Center(child: Text('Please Upload a pic'),):
it tells flutter if the path is null and not chossed show my manual message
you will see Please upload a pic in the container when you choose the image the File(Image.path); will generate an appropriate path and your pic will appear, thankyou,

TeamCity, Android, Gradle Script failure

I have been struggling to get TeamCity to build my Android Project. I have finally gotten the server to be able to compile the project with Gradlew (although I have to ignore lint errors, which I am not happy about - it will not tell me which lint errors are being violated EDIT: I found it in ..\build\outputs\lint-results.html)
But now I can see that it is trying to execute the following:
C:\TeamCity\buildAgent\work\284714bad9f1a533\MyProject>gradlew.bat --init-script C:\TeamCity\buildAgent\plugins\gradle-runner\scripts\init.gradle clean build
And I am getting the following error:
FAILURE: Build failed with an exception.
* Where:
Initialization script 'C:\TeamCity\buildAgent\plugins\gradlerunner\scripts\init.gradle' line: 31
* What went wrong:
A problem occurred evaluating initialization script.
> Cannot invoke method split() on null object
I have checked this line and it seems fairly standard:
initscript {
dependencies {
def teamCityInitLib = System.getenv("TEAMCITY_BUILD_INIT_PATH")
println "Init lib: ${teamCityInitLib}"
def classPathFiles = teamCityInitLib.split(File.pathSeparator) //line 31
classpath files(classPathFiles)
}
}
Can anyone help me? NOTE: the following command works without a problem:
gradlew.bat clean build
Seems that you don't have TEAMCITY_BUILD_INIT_PATH variable in your PATH on your build machine. You can add it either by standart ways, depending on OS, or by adding it to Build Parameters in Configuration Steps of your build.
It seems like the build file is not being found. At least, that is what support is telling me. To me this is a TeamCity bug and not on my side. When I find out more, I'll post it.
Found this post while looking for a way to emulate a TC build from the command line and trying to understand how to set TEAMCITY_BUILD_INIT_PATH.
In my environment I determined that it's set to:
/apps/teamcity-agent/agent/lib/serviceMessages.jar:/apps/teamcity-agent/agent/lib/runtime-util.jar:/apps/teamcity-agent/agent/plugins/gradle-runner/lib/gradle-runner-common.jar
Where /apps/teamcity-agent is the my TC install path.
Hope this helps.

Categories

Resources