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)
Related
I wanted:
Code coverage to run reliably against the instrumented tests
Tests to be isolated from each other
I'm new to Android development, but experienced with other development and tooling.
So I looked for the documented options and added the following to my build.gradle:
android {
defaultConfig {testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: 'true'
testInstrumentationRunnerArguments useTestStorageService: 'true'
}
buildTypes {
debug {
testCoverageEnabled true
}
}
I also have a custom task to generate the report:
task coverageReport(type: JacocoReport) {
sourceDirectories.setFrom(fileTree(
dir: "$project.buildDir/src/main/java"
))
classDirectories.setFrom(fileTree(
dir: "$project.buildDir/build/intermediates/javac/debug",
))
executionData fileTree(dir: project.buildDir, includes: [
"outputs/code_coverage/debugAndroidTest/connected/*/*.ec"
])
}
Now what I see when running the tests and generating the report, is that about 10% of the time it hits what looks like a corrupted .ec file. (the rest of the time, the report is fine)
> ./gradlew coverageReport
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:coverageReport'.
> Unable to read execution data file app/build/outputs/code_coverage/debugAndroidTest/connected/Nexus_S_API_33(AVD) - 13/com.example.coverage.ExampleInstrumentedTest#useAppContext.ec
Digging into the stack trace:
Caused by: : Unable to read execution data file app/build/outputs/code_coverage/debugAndroidTest/connected/Nexus_S_API_33(AVD) - 13/com.example.coverage.ExampleInstrumentedTest#useAppContext.ec
at org.jacoco.ant.ReportTask.loadExecutionData(ReportTask.java:518)
...
Caused by: java.io.IOException: Unknown block type 3.
at org.jacoco.core.data.ExecutionDataReader.readBlock(ExecutionDataReader.java:119)
at org.jacoco.core.data.ExecutionDataReader.read(ExecutionDataReader.java:93)
at org.jacoco.core.tools.ExecFileLoader.load(ExecFileLoader.java:60)
at org.jacoco.ant.ReportTask.loadExecutionData(ReportTask.java:516)
I've seen several other numbers in other projects for the unknown block type, but so far only 3 for this minimal example project.
MD5 sums are the same for the .ec files on and off the device:
> adb shell md5sum /data/media/0/googletest/internal_use/data/data/com.example.coverage/coverage_data/com.example.coverage.ExampleInstrumentedTest#useAppContext.ec
89c6b7ac8ad27d4d2f19dce0ac47f028 /data/media/0/googletest/internal_use/data/data/com.example.coverage/coverage_data/com.example.coverage.ExampleInstrumentedTest#useAppContext.ec
> md5sum app/build/outputs/code_coverage/debugAndroidTest/connected/Nexus_S_API_33\(AVD\)\ -\ 13/com.example.coverage.ExampleInstrumentedTest#useAppContext.ec
89c6b7ac8ad27d4d2f19dce0ac47f028 app/build/outputs/code_coverage/debugAndroidTest/connected/Nexus_S_API_33(AVD) - 13/com.example.coverage.ExampleInstrumentedTest#useAppContext.ec
Re-running the tests will generally clear the issue on this project. On a larger project, several tests fail like this on each run - different tests each time, though apparently some more than others. It doesn't appear to be linked to the running time of the test.
I tried different versions of:
Gradle (7.4, 7.5, 8.0-rc-1, 8.0-rc-2)
AGP (7.4, 8.1.0-alpha01)
Android Studio (Eel, Giraffe)
emulator SDK version (27, 31, 33)
with the same failing on each.
Syncing with Gradle files and cleaning/rebuilding don't help, and I've seen this happen on the first run of a new project.
I can see that:
Gradle support for Android lags (the new JaCoCo aggregate report plugin is explicitly not supported on Android)
Gradle's had and fixed some similar issues with JaCoCo in recent releases (e.g. https://github.com/gradle/gradle/issues/20532)
a similar issue's been seen with JaCoCo in other contexts (e.g. JaCoco MVN unknown block type which suggests the JVM's being hard-killed between tests)
Turning off clearPackageData doesn't stop these failures.
I was expecting code coverage of instrumented tests to be a core tool in my development process. So far it looks like either this error is a "me" problem, or Android devs don't see much value in having this working reliably. Any insights into why it's not that valuable or can be easily replaced would be as welcome as a fix.
I add library just like in the docs but have this issue during release build.
What exactly should be excluded?
```ERROR:/root/.gradle/caches/transforms-3/1e96e6c19d7dde614cf9997387c729bf/transformed/jetified-protolite-well-known-types-18.0.0-runtime.jar: R8: Type com.google.protobuf.DescriptorProtos$1 is defined multiple times: /root/.gradle/caches/transforms-3/1e96e6c19d7dde614cf9997387c729bf/transformed/jetified-protolite-well-known-types-18.0.0-runtime.jar:com/google/protobuf/DescriptorProtos$1.class, /opt/bamboo-agent-build-dir/JSM2-JNAD872-BMRA/libpolar/build/.transforms/028706d987454a64deaa47a7849b7551/transformed/jetified-polar-protobuf-release-runtime.jar:com/google/protobuf/DescriptorProtos$1.class
31-May-2022 10:31:19
https://firebase.google.com/docs/perf-mon/get-started-android?authuser=0
I've been trying to run my react native application, but it crashed when started and the debugger didn't return any error, so I checked the log cat in Android Studio and it shows me the following error: java.lang.NoClassDefFoundError: Failed resolution of: Lcom / google / firebase / iid / FirebaseInstanceId;
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.FirebaseInstanceId"
The React-Native version that I am using is: 0.61.5
And the version of react-native-firebase that I have installed is 5.6.0
It has already been a recent failure, since previously the app worked correctly and I have not made any changes to the firebase integration either
To debug this, first I would suggest running adb logcat and seeing what Java error you are getting. If it errors out on the not being able to find the required Java classes, then try adding the following to your project:
app/build.gradle file (dependencies section):
implementation 'com.google.firebase:firebase-iid'
(You might need to provide a version for this package as well)
I have getting same error, I fixed this error by uninstalling old version and installing new version of push notification.
uninstall:
npm uninstall react-native-push-notification
install:
npm i react-native-push-notification
since react-native-push-notification upgraded to new version v7.x so that, while installing app it give above error.
checkout this -> https://www.npmjs.com/package/react-native-push-notification
There is an issue, in react-native-push-notification (FirebaseInstanceId has been deprecated and now removed). Sounds like you are using a lib that is using that that here. It should be fixed later on, but for now you can add the following to your android/build.gradel file.
buildscript {
ext {
...
firebaseMessagingVersion = "21.0.0"
}
I had also to update these libs (you will get compile errors if you don't, so you may have others to update):
- "react-native-device-info": "^5.5.8",
+ "react-native-device-info": "^8.1.3",
- "react-native-push-notification": "^7.3.0",
+ "react-native-push-notification": "^7.3.1",
This is in reference to this issue
wix/react-native-notifications
This lib having issue with refreshToken() Method.
Didn't find class "com.google.firebase.iid.FirebaseInstanceId"
so just remove / reinstall the package, if still error is coming then we have to wait for next bug fix release of this lib or
we can manually change native code to make it working.
below is link of lib
https://github.com/wix/react-native-notifications/issues?q=FirebaseInstanceId
I'm new on react, and i tried to run my app but i got this following error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.bits.bee.bwc, PID: 12601
java.lang.AssertionError: APK bundle must contain the expected embedded asset asset_c2f3d742a18a28238b7cd34a5d4b7316.png
at expo.modules.updates.loader.EmbeddedLoader.copyAllAssets(EmbeddedLoader.java:174)
at expo.modules.updates.loader.EmbeddedLoader.processManifest(EmbeddedLoader.java:137)
at expo.modules.updates.loader.EmbeddedLoader.loadEmbeddedUpdate(EmbeddedLoader.java:57)
at expo.modules.updates.UpdatesController.start(UpdatesController.java:286)
at expo.modules.updates.UpdatesController.initialize(UpdatesController.java:96)
at com.bits.bee.bwc.MainApplication.onCreate(MainApplication.java:98)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4552)
at android.app.ActivityThread.access$1500(ActivityThread.java:147)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5255)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
Can someone explain to me how it's work because i looked it up in my asset folder there's nothing named like that. And how do i fix this? Thanks
Info
This exception only happened to me when running a debug build with react-native run-android and the exception did not appear when running a release build with react-native run-android --variant=release.
Solution
Check whether you have the following line in MainApplication.java and if it's there then remove that line:
import com.facebook.react.BuildConfig;
Explanation
The line import com.facebook.react.BuildConfig; causes UpdatesController.initialize(this); to be called in Debug mode which shouldn't happen.
More detail:
When you look at your Stacktrace you posted the line
at com.bits.bee.bwc.MainApplication.onCreate(MainApplication.java:98)
points to UpdatesController.initialize(this);. Including the line above and below that's how it looks like:
if (!BuildConfig.DEBUG) {
UpdatesController.initialize(this);
}
This BuildConfig here points to the BuildConfig class of your package (com.bits.bee.bwc in your case) which is created during the build. If you import com.facebook.react.BuildConfig it will point to another BuildConfig class which does not contain the correct DEBUG value you want.
Since BuildConfig.DEBUG will then be undefined or false, UpdatesController.initialize(this); is called although it shouldn't during a debug build. Hence, because assets will be not embedded for debug builds, the copyAllAssets function which is eventually called will not find any assets and we get the above error.
Some Context of why I ended up importing com.facebook.react.BuildConfig;
I was facing the issue of java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so in my release build and followed the advice to add that line as stated here https://stackoverflow.com/questions/57036317/react-native-java-lang-unsatisfiedlinkerror-couldnt-find-dso-to-load-libherm/63048532#answer-62119615. It didn't make a change for the release build and I forgot about it. Only later when I attempted to make a debug build I got this error.. took me quite a while to realize that this added line is the cause of the issue!
What I learned from debugging this issue:
Don't just add things because you think it won't hurt. If it doesn't fulfill a certain purpose or has no effect, remove the change immediately. It can otherwise cause strange side effects later.
If you have build issues with Android, debug with Android Studio instead of Flipper. Flipper doesn't display you the entire Stacktrace and in Android Studio you can easily browse through all the Java files which eventually helped me to understand this Exception.
Recently I had to switch to Android Studio 3.2 Canary to use the new AndroidX components.
My main development environment is Mac/OSX and everything works fine. However, this week I had to switch to Windows and when compiling the apk I'm getting the below exception.
As I'm using AndroidX, had to enable in gradle.properties file:
android.enableJetifier=true
android.useAndroidX=true
Here's the exception.
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Users\rafael.chagas\.gradle\caches\transforms-1\files-1.1\jetified-play-services-basement-15.0.1.aar\a98f8e9d46ed106e8653ab19e7672193\jars\classes.jar
at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.launchProcessing(DexArchiveBuilderTransform.java:877)
at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.lambda$convertToDexArchive$7(DexArchiveBuilderTransform.java:802)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.
at com.android.builder.dexing.D8DexArchiveBuilder.getExceptionToRethrow(D8DexArchiveBuilder.java:124)
at com.android.builder.dexing.D8DexArchiveBuilder.convert(D8DexArchiveBuilder.java:101)
at com.android.build.gradle.internal.transforms.DexArchiveBuilderTransform.launchProcessing(DexArchiveBuilderTransform.java:872)
... 6 more
Caused by: java.lang.NullPointerException: entry
at java.util.zip.ZipFile.getInputStream(ZipFile.java:346)
at com.android.tools.r8.ArchiveClassFileProvider.getProgramResource(ArchiveClassFileProvider.java:91)
at com.android.builder.dexing.r8.CachingArchiveClassFileProvider.lambda$getProgramResource$0(CachingArchiveClassFileProvider.java:38)
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
at com.android.builder.dexing.r8.CachingArchiveClassFileProvider.getProgramResource(CachingArchiveClassFileProvider.java:38)
at com.android.builder.dexing.r8.ClassFileProviderFactory$OrderedClassFileResourceProvider.getProgramResource(ClassFileProviderFactory.java:78)
at com.android.tools.r8.utils.ClassProvider$ClassFileResourceReader.collectClass(ClassProvider.java:97)
at com.android.tools.r8.utils.ClassMap$ConcurrentClassLoader.get(ClassMap.java:241)
at com.android.tools.r8.utils.ClassMap$ConcurrentClassLoader.get(ClassMap.java:217)
at com.android.tools.r8.utils.ClassMap.get(ClassMap.java:115)
at com.android.tools.r8.graph.LazyLoadedDexApplication.definitionFor(LazyLoadedDexApplication.java:47)
at com.android.tools.r8.graph.AppInfo.definitionFor(AppInfo.java:62)
at com.android.tools.r8.ir.desugar.InterfaceMethodRewriter.findDefinitionFor(InterfaceMethodRewriter.java:255)
at com.android.tools.r8.ir.desugar.InterfaceMethodRewriter.rewriteMethodReferences(InterfaceMethodRewriter.java:140)
at com.android.tools.r8.ir.conversion.IRConverter.rewriteCode(IRConverter.java:675)
at com.android.tools.r8.ir.conversion.IRConverter.convertMethodToDex(IRConverter.java:346)
at com.android.tools.r8.graph.DexClass.forEachMethodThrowing(DexClass.java:132)
at com.android.tools.r8.ir.conversion.IRConverter.lambda$convertClassesToDex$2(IRConverter.java:332)
at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:117)
at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:38)
at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:77)
at com.google.common.util.concurrent.MoreExecutors$DirectExecutorService.execute(MoreExecutors.java:260)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134)
at com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:66)
at com.google.common.util.concurrent.AbstractListeningExecutorService.submit(AbstractListeningExecutorService.java:36)
at com.android.tools.r8.ir.conversion.IRConverter.convertClassesToDex(IRConverter.java:330)
at com.android.tools.r8.ir.conversion.IRConverter.convertToDex(IRConverter.java:245)
at com.android.tools.r8.D8.optimize(D8.java:202)
at com.android.tools.r8.D8.run(D8.java:162)
at com.android.tools.r8.D8.lambda$run$1(D8.java:92)
at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:56)
at com.android.tools.r8.utils.ExceptionUtils.withD8CompilationHandler(ExceptionUtils.java:41)
at com.android.tools.r8.D8.run(D8.java:89)
at com.android.builder.dexing.D8DexArchiveBuilder.convert(D8DexArchiveBuilder.java:99)
The target .jar file above is random. It may fail with any of the project libraries.
I know that this is a Canary release of Android Studio, but what intrigues me is that this only occurs with Windows OS. Tested in Linux, OSX and had no problems at all.
Thanks!
Finally I found the root cause and fix to this issue.
Looking into the error messages, the Android R8 class causing the exception was:
src/main/java/com/android/tools/r8/ArchiveClassFileProvider.java
Digging into R8 source i found the latest logs and a brand new commit that changes the encoding while reading .zip files:
https://r8.googlesource.com/r8/+/a26659a1d07b4dc4ad0c3f8dbafd47d49efbc438
This commit changes the way R8 reads zip archives using UTF-8 encoding and avoid using the platform encoding. That's why only Windows was failing.
I tested the latest R8 release with that commit and it worked! Just need to add these (+) lines to your project build.gradle file.
repositories {
google()
jcenter()
+ maven {
+ url "http://storage.googleapis.com/r8-releases/raw"
+ }
}
dependencies {
+ classpath 'com.android.tools:r8:1.2.28'
classpath 'com.android.tools.build:gradle:3.2.0-alpha18'
classpath 'com.google.gms:google-services:4.0.0'
}
The "com.android.tools:r8:1.2.28" must be the first one in the dependencies.
According to the BUG 109992855 that new version of R8 will be pushed to Android Studio 3.2 in about two weeks. Meanwhile you must use the above fix.
Hope that helps anyone who stumbled on this error.