Android Studio Unable to Build Module with Cross Module Dependancy - android

I have a project with 4 modules, say A, B, C, D. Module C is a container for common code in A, B and D. Module C uses Wire to generate Java Code from Protobuffers. Module B depends on both module C and D. I have only one compile project dependancy in B though, as B compiles D compiles C..
It was all working fine till Android Studio Update last year, when I "lost the editor", i.e. modules were still building nicely, but Android Studio when editing in module A and B missed the generated Java classes and painted my code "fairly" red, i.e. generated classes from C became unknown to the editor, losing syntax completion and all other stuff.
After opening a ticket at Google nothing happened. I went a while with the workaround having
sourceSets {
main.java.srcDirs += '../common/build/generated/source/java/'
}
in my (A or B) gradle. Which kept the editor intact, the project was building anyway.
With Android Studio 3.0 I do not get my modules built any more. With above sourceset line I end up with the dexer finding duplicate classes
Information:Gradle tasks [:app:assembleDebug]
Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lde/spieleck/app/badgers/messages/BadgeMsg$Builder;
Error:com.android.dex.DexException: Multiple dex files define Lde/spieleck/app/badgers/messages/BadgeMsg$Builder;
Error: at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
Error: at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
Error: at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
Error: at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
Error: at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
Error: at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
Error: at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
Error: at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1445)
Error: at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
Error: at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:902)
Error: at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1689)
Error: at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1644)
Error: at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error:Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Lde/spieleck/app/badgers/messages/BadgeMsg$Builder;
Information:BUILD FAILED in 8s
Information:BUILD 61 FINISHED; failure=org.gradle.internal.exceptions.LocationAwareException: Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
Information:16 errors
Information:0 warnings
Information:See complete output in console
Without above gradle lines, I end up with the compiler not finding code:
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Unable to find source java class: 'D:\00meins\AndroidStudioProjects\Badgers-UI\common\build\generated\source\java\de\spieleck\app\badgers\messages\BadgeMsg.java' because it does not belong to any of the source dirs: '[D:\00meins\AndroidStudioProjects\Badgers-UI\app\src\main\java, D:\00meins\AndroidStudioProjects\Badgers-UI\app\src\debug\java, D:\00meins\AndroidStudioProjects\Badgers-UI\app\build\generated\source\r\debug, D:\00meins\AndroidStudioProjects\Badgers-UI\app\build\generated\source\buildConfig\debug, D:\00meins\AndroidStudioProjects\Badgers-UI\app\build\generated\source\aidl\debug, D:\00meins\AndroidStudioProjects\Badgers-UI\app\build\generated\source\rs\debug]'
Confused remark: When desparately I tried to downgrade gradle, gradle tools etc. withom Android Studio to state of previous Android Studio release gave up half the way due to more and more dependencies and got things back to the state that AS3.0 delivers and my modules built.
However after restarting AS3.0 I am back in above dilemma. I mean I cannot really edit my gradle settings back and forth everytime to get the built working.
Any suggestion how to set up my dependencies better or fix all compiling, building and syntax highlighting?
I am AFK now for a long weekend, hoping for answers early next week.
References:
G+: https://plus.google.com/u/0/+FrankNestel/posts/c177h2R1qJz
Google issue: https://issuetracker.google.com/issues/37120454

This is not a super answer, as things are complicated and real world. But Google support kindly inspected my setup and found out, that a certain source setting for generated code had become required, that was optional under AS2.2.
So, it probably won't happen, if you start with AS3 anyway. But as things got messy over time and suddenly stopped to work after migration, this wasn't exactly obvious to spot.

Related

Gradle build failure when packaging GooglePAD asset packs in Unreal Engine

I have followed this guide to implement the GooglePAD plugin in UE 4.27, but I'm met with the following error when I try to package the project for the second time (first time generates the asset packs):
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:assetPackDebugPreBundleTask'.
> Could not resolve all task dependencies for configuration ':app:assetPackFiles'.
> Could not resolve project :assetpacks:on-demand:OnDemandPack.
Required by:
project :app
> Project :app declares a dependency from configuration 'assetPackFiles' to configuration 'packElements' which is not declared in the descriptor for project :assetpacks:on-demand:OnDemandPack.
I see that there is a similar question here, but their solution doesn't seem to apply to me since I'm certain my folders are properly named. This happens with all 3 of my on-demand packs. The build.gradle file inside the asset pack folders is exactly the same as the one included in the guide, though I have tried just writing the pack names as shown here to no avail.
What should I do to build successfully with this plugin?

Play-Services-Maps and Android Studio 3.3 issue with AndroidX involving Annotation library

I've recently updated my project to build from Android Studio 3.3, which involved making the following changes (prompted on Android Studio startup):
build.gradle dependency:
classpath 'com.android.tools.build:gradle:3.3.0'
gradle-wrapper:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
This produced a number of errors in a feature module when trying to sync which uses Google Maps. I'm using version 16.0.0 of play-services-maps:
implementation "com.google.android.gms:play-services-maps:16.0.0"
The errors that appeared when trying to sync gradle were:
ERROR: Unable to resolve dependency for ':featureModule#flavorDebugFeature/compileClasspath': Could not resolve androidx.annotation:annotation:1.0.0.
ERROR: Unable to resolve dependency for ':featureModule#flavorDebugFeature/compileClasspath': Could not resolve androidx.annotation:annotation:1.0.1.
ERROR: Unable to resolve dependency for ':featureModule#flavorDebugFeature/compileClasspath': Could not resolve androidx.core:core:1.0.0.
ERROR: Unable to resolve dependency for ':featureModule#flavorDebugFeature/compileClasspath': Could not resolve androidx.core:core:1.0.1.
This is repeated for every possible flavour variant combination in this module.
It's worth pointing out that this project was migrated to androidX some months ago and has been working fine.
The fix for the errors are to add the following to the gradle dependencies for that failing module:
implementation "androidx.annotation:annotation:1.0.1"
implementation "androidx.core:core:1.0.1"
The app then compiles fine and runs on device. Perfect. Until we try and run lint in a CI build before release on the project, and we hit a spot of bother, with the error message:
Execution failed for task ':featureModule:lintFlavorDebug'.
> Lint infrastructure error
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
... [several lines omitted for brevity]
Caused by: java.lang.IllegalStateException: Expected task 'processFlavorDebugAndroidTestJavaRes' output files to contain exactly one file, however, it contains no files.
at org.gradle.api.internal.file.AbstractFileCollection.getSingleFile(AbstractFileCollection.java:65)
at com.android.build.gradle.internal.variant.BaseVariantData.getJavaResourcesForUnitTesting(BaseVariantData.java:700)
at com.android.build.gradle.internal.ide.ModelBuilder.createAndroidArtifact(ModelBuilder.java:992)
at com.android.build.gradle.internal.ide.ModelBuilder.createVariant(ModelBuilder.java:617)
at com.android.build.gradle.internal.ide.ModelBuilder.buildAndroidProject(ModelBuilder.java:399)
at com.android.build.gradle.internal.ide.ModelBuilder.buildAll(ModelBuilder.java:212)
at com.android.tools.lint.gradle.LintGradleExecution.createAndroidProject(LintGradleExecution.java:352)
at com.android.tools.lint.gradle.LintGradleExecution.analyze(LintGradleExecution.java:85)
... 59 more
This issue goes away if we remove the 2 new dependencies (plus Google Maps, which seems to be the cause of the requirement for the core and annotations libraries).
I've done some searching both here and via Google, and the Expected task 'processFlavorDebugAndroidTestJavaRes' output files to contain exactly one file, however, it contains no files. exception has been seen by others, and their solution is to make sure the base build.gradle file has the baseFeature true flag in defaultConfig, which is already present in my project.
I'm now stuck for where to go next in trying to solve this issue.

com.android.dex.DexException: Multiple dex files define Ledu/hawhamburg/vuforia/BuildConfig;

An Android project I've been working on for the better part of the last year doesn't work ever since I've bought a new laptop, and I just don't know what to do anymore.
The project itself contains of five subprojects that get included with a settings.gradle file.
Gradle tasks [:app:assembleDebug]
Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Ledu/hawhamburg/vuforia/BuildConfig;
com.android.dex.DexException: Multiple dex files define Ledu/hawhamburg/vuforia/BuildConfig;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:661)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:616)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:598)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:198)
at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:61)
at com.android.builder.dexing.DexArchiveMergerCallable.call(DexArchiveMergerCallable.java:36)
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)
Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: com.android.dex.DexException: Multiple dex files define Ledu/hawhamburg/vuforia/BuildConfig;
BUILD FAILED in 12s
15 errors
0 warnings
Things I've tried: Updating Gradle, updating Android Studio, clean project, re-clone gitlab project, delete Gradle cache, and also this:
android {
dexOptions {
preDexLibraries = false
}
}
If explicitly disabling pre-dexing doesn't prevent the DexException from appearing, something is seriously screwed up. I just don't know how to find the cause.
Again, this worked on my old computer just fine, so whatever it is, it has to be related to the environment.
I thing that your project have some Android libraries? If yes, all AndroidManifest.xml file must have different package attribute in manifest tag.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="<<DIFFERENT VALUE HERE>>">
<application>
...
By the way, after changing this, you have to manually delete the build directory of the library. clean doesn't delete old BuildConfig file.

Multiple Dex File build error following NS 2.5 Upgrade

Following the upgrade to Nativescript 2.5 I'm receiving a build error that I'm not quite sure how to fix. The error is:
Execution failed for task ':transformClassesWithDexForF0F1F2F3F4F5F6Debug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files
define Lcom/google/android/gms/iid/MessengerCompat$1;
I've spent some time looking into the issue and a Multiple Dex file exception seems to normally mean that two different versions of a dependency are being referenced. Yet I can't seem to find anything which relates to > MessengerCompat in the gradle files of any of my dependencies.
Thanks for any help!
For your case you could try to remove node_modules, platforms and hooks folders from your project and to clear npm cache with npm cache clear.
Then try to rebuild the app with tns run android.
It would also help if you could share the package.json file of the project.

Build failed with an exception

I am getting Task 'jar' is ambiguous in root project 'ProjectName'.
Candidates are: 'jarDebugClasses', 'jarReleaseClasses'.
while i run ./gradlew clean jar
can anybody help me out.
The error information basically says what is wrong: gradle cannot determine which task you are trying to run as jar is short for both jarDebugClasses as well as jarReleaseClasses. Replacing jar with jarR will solve the ambiguity (if you want to trigger the jarReleaseClasses task - use jarD for jarDebugClasses).

Categories

Resources