Using gradle implementation of my flavoured Library causes java.lang.NoClassDefFoundError - android

Hey everyone I have my own developed SDK in where I few external libraries, everything works fine if the flavour is default type but issue occurs when i change the flavour then I get java.lang.NoClassDefFoundError: Failed resolution of: Lcom/github/mikephil/charting/data/LineData;
and on every library that is implemented in my SDK
i searched all over and couldn't find any solution to it
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/github/mikephil/charting/data/LineData;

Related

Failed to build when using fragment testing library on AndroidGradlePlugin 3.5.0 and above for Dynamic Feature module

So, I was trying to use fragment testing library androidx.fragment:fragment-testing:1.2.4 in a dynamic feature module. When I used Android Gradle Plugin (AGP) version 3.6.3, it failed to build with an error
AAPT: error: resource style/FragmentScenarioEmptyFragmentActivityTheme (aka com.example.reminder.test:style/FragmentScenarioEmptyFragmentActivityTheme) not found.
And so I was curious and checkout the codelab github and try to upgrade the AGP on that project to 3.6.3 and it can build successfully. But the codelab does not use Dynamic Features.
So I tried to actually run a fragment test in my app module only (excluding the dynamic features module) and yes it can build successfully too.
But I still need to test my fragment in the dynamic features module, so I tried playing with the version one by one and then when I downgrade the AGP version to 3.4.1 it can build successfully.
And I found out that since AGP version 3.5.0 and above, it just failed to build with the same error above.
So,
AGP 3.5.0 and above:
- Building test on app module only -> works
- Building test on dynamic features -> failed to build
AGP 3.4.2 and below:
- Building test on app module only -> works
- Building test with dynamic features -> works
But I still want to use AGP 3.6.0 because I want to utilise viewBinding.
So does anyone know how to resolve the error above for fragment testing with dynamic features module?
Upgrading AGP to 4.0.0 and above should resolve the issue.

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.

Android Studio 3.1 gradle build throws java.util.zip.ZipException

I'm getting this during gradle builds after the upgrade to Android Studio 3.0:
Execution failed for task
':lf-android-myproject:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug'.
java.lang.RuntimeException: java.util.zip.ZipException: duplicate entry: com/my/package/name/SomeCustomView.class
The class in question comes from my code, it's not from a library.
It happens only with my classes that have custom attributes declared:
<declare-styleable name="SomeCustomView">
<attr name="someCustomViewText" format="reference|string" />
</declare-styleable>
I can fix it by cleaning and then building from the console, but it pops up again eventually.
I can fix it also by renaming the class or the styleable, but I really don't want to mess with our code just to go around an AS (or gradle?) bug that can be fixed in the future probably.
Is it an Android Studio bug? Are there any workarounds?
Gradle version is: gradle-4.1-all
Android Gradle plugin version is: 3.0.1
This issue can be found for different reason. However, Here is a way to fix Gradle build error: “java.util.zip.ZipException: duplicate entry”
If you’ve updated some libraries in your android project and then encountered the following error while assembling it (or something similar):
The reason is that some libraries have similar dependencies, therefore the compiler can not choose the appropriate one.
According to the logs, the problem in the duplicated class
org/intellij/lang/annotations/Identifier.class
To find this class usages, you should filter the detailed gradle log:
Fix it!
Remove one of the dependencies:
Follow this for your case and I guess you will find your solution.
I solved this by deleting Android Studio files from the project and re-importing the project.

Why do I get a different number of methods after proguard using maven and gradle

I have a project with with a big number of third party libraries.
So I use pro-guard.
I build project using maven.
After migrating project to gradle I get error:
"trouble writing output: Too many method references: 66062; max is 65536."
Any idea?

Android Studio. Error: (24, 24) failed to resolve

I am taking Coursera Programming Mobile Applications for Android handheld systems course and when I try to run labs I get the error:
(24, 24): failed to resolve:
com.jayway.android.robotium:robotium-solo:5.3.1
My system is using a Proxi, but I adjust AS so updates and component are available. What should I do to resolve this error?
To be able to use a lib project you need to include it in your application's settings.gradle add:
include '..:ExpandableButtonMenu:library'
compile project(':..:ExpandableButtonMenu:library')
Good link visit "how to build an android library with android studio and gradle

Categories

Resources