I'am using the EasyPermission library and when I want to accept a storage permission, my application crash with the following StackTrace:
java.lang.NoClassDefFoundError: android.app.PictureInPictureParams
at libcore.reflect.InternalNames.getClass(InternalNames.java:55)
at java.lang.Class.getDexCacheType(Class.java:2551)
at java.lang.reflect.AbstractMethod.getParameterTypes(AbstractMethod.java:169)
at java.lang.reflect.Method.getParameterTypes(Method.java:193)
at java.lang.Class.getDeclaredMethods(Class.java:1812)
at pub.devrel.easypermissions.EasyPermissions.runAnnotatedMethods(EasyPermissions.java:368)
at pub.devrel.easypermissions.EasyPermissions.onRequestPermissionsResult(EasyPermissions.java:240)
at com.my.app.base.BaseActivity.onRequestPermissionsResult(BaseActivity.java:489)
at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7458)
at android.app.Activity.dispatchActivityResult(Activity.java:7284)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4516)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4563)
at android.app.ActivityThread.-wrap22(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1698)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.app.PictureInPictureParams" on path: DexPathList[[zip file "/data/app/com.my.app.debug-2/base.apk"],nativeLibraryDirectories=[/data/app/com.my.app..debug-2/lib/arm, /data/app/com.my.app.debug-2/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at libcore.reflect.InternalNames.getClass(InternalNames.java:53)
at java.lang.Class.getDexCacheType(Class.java:2551)
at java.lang.reflect.AbstractMethod.getParameterTypes(AbstractMethod.java:169)
at java.lang.reflect.Method.getParameterTypes(Method.java:193)
at java.lang.Class.getDeclaredMethods(Class.java:1812)
at pub.devrel.easypermissions.EasyPermissions.runAnnotatedMethods(EasyPermissions.java:368)
at pub.devrel.easypermissions.EasyPermissions.onRequestPermissionsResult(EasyPermissions.java:240)
at com.my.app.base.BaseActivity.onRequestPermissionsResult(BaseActivity.java:489)
at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:7458)
at android.app.Activity.dispatchActivityResult(Activity.java:7284)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4516)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4563)
at android.app.ActivityThread.-wrap22(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1698)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
What you should notice is that it happen on both RELEASE and DEBUG version.
Here is my gradle file:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.22.2'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dexOptions {
javaMaxHeapSize "4g"
}
signingConfigs {
release_config {
[not showing it here]
}
}
compileSdkVersion 27
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.my.app"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "x"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
dataBinding {
enabled = true
}
// workaround for "duplicate files during packaging of APK" issue
// see https://groups.google.com/d/msg/adt-dev/bl5Rc4Szpzg/wC8cylTWuIEJ
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
//Workaround to an issue due to google play-services 11.0.0 + rxJava
exclude 'META-INF/rxjava.properties'
}
buildTypes {
release {
debuggable false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release_config
}
debug {
applicationIdSuffix ".debug"
versionNameSuffix " - debug"
debuggable true
}
}
flavorDimensions "public"
productFlavors {
dev {
dimension "public"
}
prod {
dimension "public"
}
}
}
//Define gradle variables
ext {
supportLibVersion = '27.0.2'
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'org.jetbrains:annotations-java5:15.0'
//Support Libraries
compile "com.android.support:appcompat-v7:${supportLibVersion}"
compile "com.android.support:support-v4:${supportLibVersion}"
compile "com.android.support:support-v13:${supportLibVersion}"
compile "com.android.support:design:${supportLibVersion}"
compile "com.android.support:recyclerview-v7:${supportLibVersion}"
compile "com.android.support:cardview-v7:${supportLibVersion}"
compile 'com.google.android.gms:play-services-auth:11.6.2'
compile 'com.android.support.constraint:constraint-layout:1.1.0-beta3'
//Google Collections -> Known as Guava. Provides tools to work with collections.
compile 'com.google.guava:guava:22.0-android'
//Google FlexBox -> Flexible layout to handle unknown number of children.
compile 'com.google.android:flexbox:0.2.3'
//Fragment Args -> Library using annotation to simplify the process of passing arguments to a fragment
compile 'com.hannesdorfmann.fragmentargs:annotation:3.0.2'
annotationProcessor 'com.hannesdorfmann.fragmentargs:processor:3.0.2'
//Dart -> Library using annotation to simplify the process of passing arguments to an activity
compile 'com.f2prateek.dart:dart:2.0.0'
annotationProcessor 'com.f2prateek.dart:dart-processor:2.0.0'
//Dagger -> Library used for dependencies injections
compile 'com.google.dagger:dagger:2.2'
annotationProcessor 'com.google.dagger:dagger-compiler:2.2'
//GSON -> Library to simplify Json parsing
compile 'com.google.code.gson:gson:2.8.0'
//Couchbase -> NoSQL Database Manager
compile 'com.couchbase.lite:couchbase-lite-android:1.4.0'
compile 'com.couchbase.lite:couchbase-lite-android-sqlcipher:1.4.0'
//Retrofit -> Library developed by Square. Used to communicate with Restful API.
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
//AVLoading -> Provides multiple loaders.
compile 'com.wang.avi:library:1.0.5'
compile 'com.nineoldandroids:library:2.4.0'
//Crashlytics -> Crash reporting library. Developed by Fabric.
compile('com.crashlytics.sdk.android:crashlytics:2.6.7#aar') {
transitive = true
}
//Faker -> Library to create fake data
compile 'com.github.thiagokimo:faker:1.4.3'
//MaterialSearchView -> Provides a styled material searchView.
compile 'com.miguelcatalan:materialsearchview:1.4.0'
//LovelyDialog -> Provide beautiful and easy to use dialogs
compile 'com.yarolegovich:lovely-dialog:1.0.4'
//TextDrawable -> Provides images with text, useful for profile avatar (eg: Gmail).
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
//2D ScrollView
compile 'com.jaredrummler:twodscrollview:1.0.1'
//RecyclerViewTools -> Tools for RecyclerView (Headers, Footers, Sections, etc).
compile 'com.eyeem.recyclerviewtools:library:0.4.0'
//RopeProgressBar -> A sweet animated progress bar
compile 'com.github.cdeange:RopeProgressBar:0.1.2'
//AsyncJob -> Simplify the use of AsyncTask.
compile 'com.arasthel:asyncjob-library:1.0.3'
//Simple -> Xml Parser
compile ('org.simpleframework:simple-xml:2.7.1') {
exclude group: 'xpp3', module: 'xpp3'
exclude group: 'stax', module: 'stax-api'
exclude group: 'stax', module: 'stax'
}
//RxAndroid -> Reactive Android. Library that implement Observable/Reactive pattern for Android.
compile 'io.reactivex:rxandroid:1.2.1'
// Because RxAndroid releases are few and far between, it is recommended to
// explicitly depend on RxJava's latest version for bug fixes and new features.
compile 'io.reactivex:rxjava:1.1.6'
//Leak Canary -> Detect memory leaks.
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'
//Material about -> Library to build neat about page
compile 'com.github.daniel-stoneuk:material-about-library:2.2.1'
//Stetho -> used to analyze application (database, shared-preferences, traffic network, etc)
compile 'com.facebook.stetho:stetho:1.5.0'
compile 'com.robotpajamas.stetho:stetho-couchbase:0.2.0'
compile project(path: ':security')
//Apache commons lang 3 -> contains utilities such as ClassUtils
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
//ExpandableRecyclerView -> Implementation of ExpandableListView for RecyclerView
compile 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'
//TextDecorator -> Easy to implements span etc.
compile 'com.tuyenmonkey:text-decorator:1.0.0'
//EasyPermission -> Helper for Android-M permissions
compile 'pub.devrel:easypermissions:1.0.0'
// CompositeAndroid -> Library that make uses of plugins to inject into Activities and Fragments
// instead of using inheritance trees.
// contains CompositeActivity
compile "com.pascalwelsch.compositeandroid:activity:26.0.0"
// contains CompositeFragment and CompositeDialogFragment
compile "com.pascalwelsch.compositeandroid:fragment:26.0.0"
// core module (not required, only abstract classes and utils)
compile "com.pascalwelsch.compositeandroid:core:26.0.0"
}
I already tried a few things:
Clean/Rebuild
Disabling Instant Run
Asked on the GitHub page of EasyPermission but resulted in a 'not an error due to the library' (which is right)
Adding a file on "multiDexKeepFile"
Adding a file on "multiDexKeepProguard"
For the point 4 and 5 here is how I created my files (maybe I did it wrong):
MultiDexKeepFile
android/app/PictureInPictureParams.class
MultiDexKeepProguard
-keep class android.app.PictureInPictureParams
And I added them both on the root of my project and under the 'app' directory (same level as the gradle file). I obviously added the corresponding lines of the multiDexKeepFile and multiDexKeepProguard into the gradle file as well but it didn't changed anything.
I aslo checked inside the dex files of my APK but didn't find the android.app.PictureInPictureParams.
Nothing I tried fixed my issue. What should I do so?
Let me explain with some other library (EventBus) but with the same context as asked by OP. In android os version less than oreo, I was getting the crash logs.
Reference: https://github.com/greenrobot/EventBus/issues/595
Additional Reference for the same:
https://github.com/greenrobot/EventBus/issues/149
https://github.com/greenrobot/EventBus/issues/556
Owner of the GreenBot has also updated the FAQ for the same:
http://greenrobot.org/eventbus/documentation/faq/
Cause of error:
The exception is thrown if the class has methods with a parameter that is unavailable to the API level of the device.
Example: the class PersistableBundle was added in API level 21. Along with the new class some new life cycle methods were introduced in the class Activity having PersistableBundle as a parameter, for example, onCreate (Bundle savedInstanceState, *PersistableBundle* persistentState). Now, if you override this method and you try to register this Activity to EventBus on an older device, we have exactly the scenario described to cause to bug.
Possible Suggestions:
Maybe you overwrote a life cycle method with PersistableBundle just by accident. In that case just change to the method without PersistableBundle, for example onCreate (Bundle savedInstanceState).
Use EventBus 3 with an subscriber index. This will avoid reflection
and thus the problem altogether. As a positive side effect,
registering subscribers and thus app startup time will be much
faster.
Remove the offending method from your subscriber class. Either pull
out the event handler methods into a new subscriber class, or pull
out the offending method into a non-subscriber class.
If the offending method is public, make it non-public. This works
because of some “plan b” logic EventBus applies: EventBus first
calls getDeclaredMethods, which will fail. Next, EventBus will try
again using the getMethods (“plan b”). The latter will succeed
because getMethods only returns public methods. However, keep in
mind that is the least efficient way in terms of performance (2
reflection calls instead of 1 with getMethods considering the entire
class hierarchy).
I used a private modifier for my problem [Suggetion #4].
Related
I'm currently developing an Android application, which is required to read/write data from/to an Excel spreadsheet (.xls or .xlsx).
In order to integrate Android <--> Excel I am using this poi library, mainly because I was having some issues with correctly configuring the dependencies to the original Apache POI.
Note: On an action performed (button click), a workbook object is instantiated as such this.workbook = new XSSFWorkbook(super.file);
Following is the content of my build.gradle (module) file:
apply plugin: 'com.android.application
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.ricardomiranda.expenses"
minSdkVersion 24
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
// Workaround - "Program type already present"
dexOptions {
preDexLibraries = false
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:27.1.1'
// Workaround - "com.bea.xml.stream.EventFactory not found"
implementation('com.fasterxml:aalto-xml:1.0.0'){
// Workaround - "Program type already present"
exclude module: 'stax'
exclude module: 'stax-api'
exclude module: 'xpp3'
exclude group: 'com.android.support'
exclude module: 'support-v7'
exclude module: 'fasterxml'
}
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation files('libs/poishadow-all.jar')
}`
As one can observe, the previous code snippet has some workaround inclusions (properly highlighted by the comments) in order to try to solve the problems I'm facing, yet to no avail.
The issues:
Consider the previous build.gradle code snippet without the workarounds
The build is successfully executed and the application is launched. On a button click, the aforementioned line is executed: this.workbook = new XSSFWorkbook(super.file); as well as some other classes and methods inherited from the poi library - this button is trying to write data into an Excel spreadhseet. However, the expected behaviour is not applied, as the execution is aborted with a "fatal exception" as such:
`
2019-01-31 18:35:14.377 20682-20682/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ricardomiranda.expenses, PID: 20682
org.apache.poi.javax.xml.stream.FactoryConfigurationError: Provider com.bea.xml.stream.EventFactory not found
at org.apache.poi.javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:72)
at org.apache.poi.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:178)
at org.apache.poi.javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
at org.apache.poi.javax.xml.stream.XMLEventFactory.newInstance(XMLEventFactory.java:30)
at org.apache.poi.openxml4j.opc.internal.marshallers.PackagePropertiesMarshaller.<clinit>(PackagePropertiesMarshaller.java:41)
at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:161)
at org.apache.poi.openxml4j.opc.OPCPackage.<init>(OPCPackage.java:141)
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:130)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:295)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:201)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:323)
at com.ricardomiranda.expenses.ExcelManagement.initializeWorkbook(ExcelManagement.java:141)
at com.ricardomiranda.expenses.ExcelManagement.<init>(ExcelManagement.java:51)
at com.ricardomiranda.expenses.AddExpense$1.onClick(AddExpense.java:44)
at android.view.View.performClick(View.java:6291)
at android.view.View$PerformClick.run(View.java:24931)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7529)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
In order to remediate the issue and based on this comment, I added the following dependency to my build implementation('com.fasterxml:aalto-xml:1.0.0') and set the required system properties (also described in the Getting started section of the library's README documentation).
Relaunching the application after applying the former changes results in the next error, this time during the project's build:
Error: Program type already present: com.fasterxml.aalto.ValidationException
As far as I can tell this seems to be a duplicated dependency problem, but I can't resolve gradlew app:dependencies (the output is way too extensive) and no configurations are outputted by analogous commands.
I have used this guide to build persistence with Room in my Android App:
https://developer.android.com/training/data-storage/room/index.html
and added dependances like shown here:
https://developer.android.com/topic/libraries/architecture/adding-components.html
when i build the debug version and deply to phone, everithing works fine.
When i build the release signed APK i got this error message:
Error:Error: json defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
my app.gradle:
apply plugin: 'com.android.application'
android {
signingConfigs {
/* TODO(developer): Configure to sign app with a release key for testing.
release {
storeFile file('path/to/release/signing/key')
keyAlias 'release_key_alias'
keyPassword "${password}"
storePassword "${password}"
}*/
}
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "myappid"
minSdkVersion 14
targetSdkVersion 23
versionCode 10
versionName "1.8"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// TODO(developer): uncomment below once config above is complete and uncommented.
//signingConfig signingConfigs.release
}
}
}
configurations {
all {
exclude module: 'httpclient'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:26.1.0'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.volley:volley:1.0.0'
compile 'com.github.nkzawa:socket.io-client:0.3.0'
compile 'io.socket:socket.io-client:0.8.3'
compile 'com.android.support:design:26.1.0'
compile 'android.arch.persistence.room:runtime:1.0.0'
implementation "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
}
my project.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
//classpath 'io.socket:socket.io-client:0.8.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
ext{
roomVersion = '1.0.0'
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
}
}
Somebody can help or give me clues?
I finally found the problem was a JSON sub-module:
compile 'com.github.nkzawa:socket.io-client:0.3.0'
this library has a submodule:
org.json:json
that is now conflicting with android native module, because in my other dependancies i can't find this one. It was working fine 10 days ago.
I also had to kill this:
compile 'io.socket:socket.io-client:0.8.3'
the final solution was to add an exclude for the module and change the line like this:
implementation ('com.github.nkzawa:socket.io-client:0.3.0',{
exclude group:'org.json', module:'json'
})
I also have noticed AFTER i solved the problem that in the error log it was suggesting me the module that was in conflict but even if i read it a hundred times i didn't noticed before:
so maybe google or Intellij could improve the writing of this errors...
To spot this class duplicate conflict error module i found the best way to proceed is to create a new project and paste in the dependancies in app build.gradle, and check them one by one or with "dividi et impera", maybe this is an obvious suggestion for someone but i would have like to have it sooner.
I had the same problem and I searched for the conflict via the gradle dependency tree:
gradlew app:dependencies
Then I excluded the the json module for the conflicting library:
implementation ('<conflicting-library>',{
exclude group:'org.json', module:'json'
})
How to find the duplicate library.
open gradle run window and run such command:
gradle module-name:dependencies
the "module-name" should be your app module's name, for me, it's "osmunda-demo".
then use Ctrl+F to search "commons-logging", you'll find it.
#Romeo has suggested a really great point. Was unable to debug the code for hours. The problem lies within the dependencies that are imported in build.gradle. It may be your own custom sdk/artifact. I had issues with my own library which uses jjwt. I added the exclusion in my sdk but you will have to add it again whenever using the sdk. Make sure to add exclude group: 'org.json', module: 'json' in your artifact implementation.
I created a new project in Android Studio 2.2 Preview 1 with Android App and Backend module with Google Messaging. This is the app file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.xxx.xxx"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha1'
compile 'com.google.android.gms:play-services-gcm:9.0.0'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support:support-annotations:23.4.0'
compile project(path: ':backend', configuration: 'android-endpoints')
}
But it's giving:
Error:Conflict with dependency 'com.google.code.findbugs:jsr305'. Resolved versions for app (1.3.9) and test app (2.0.1) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
I am new to Android and not able to find what is this error. How do I fix it?
In your app's build.gradle add the following:
android {
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
}
Enforces Gradle to only compile the version number you state for all dependencies, no matter which version number the dependencies have stated.
This is due to espresso. You can add the following to your apps build.grade to mitigate this.
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
exclude group: 'com.google.code.findbugs'
}
METHOD 1:
I deleted the androidTestCompile on espresso-core line which was automatically included in a new project. Then my Android Studio compiles clean.
The androidTestCompile is in "build.gradle (Module:app)":
dependencies {
...
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
...
}
I don't know whether this deletion will have any problem down the road, but it surely works for my current project now.
METHOD 2: Adding an exclude on findbugs works too:
dependencies {
...
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.code.findbugs'
})
...
}
METHOD 3: Forcing compiling with a specific version:
(In the following I force it to compile with the higher version.)
dependencies {
...
androidTestCompile 'com.google.code.findbugs:jsr305:3.0.0'
...
}
From Gradle Plugin User Guide:
When instrumentation tests are run, both the main APK and test APK share the same classpath. Gradle build will fail if the main APK and the test APK use the same library (e.g. Guava) but in different versions. If gradle didn't catch that, your app could behave differently during tests and during normal run (including crashing in one of the cases).
To make the build succeed, just make sure both APKs use the same version. If the error is about an indirect dependency (a library you didn't mention in your build.gradle), just add a dependency for the newer version to the configuration
Add this line to your build.gradle dependencies to use newer version for both APKs:
compile('com.google.code.findbugs:jsr305:2.0.1')
For future reference, you can check your Gradle Console and it will provide a helpful link next to the error to help with any gradle build errors.
The reason why this happen is that diff dependency use same lib of diff version.
So, there are 3 steps or (1 step) to solve this problem.
1st
Add
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:2.0.1'
}
to your build.gradle file in android {...}
2nd
Open terminal in android studio
run ./gradlew -q app:dependencies command.
3rd
Click Clean Project from menu bar of android studio in Build list.
It will rebuild the project, and then
remove code in 1st step.
Maybe you need just exec 2nd step. I can't rollback when error occurs.
Have a try.
When I added module: 'jsr305' as an additional exclude statement, it all worked out fine for me.
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
exclude module: 'jsr305'
})
The problem, as stated in your logs, is 2 dependencies trying to use different versions of 3rd dependency.
Add one of the following to the app-gradle file:
androidTestCompile 'com.google.code.findbugs:jsr305:2.0.1'
androidTestCompile 'com.google.code.findbugs:jsr305:1.3.9'
The accepted answer is one way of fixing the issue, because it will just apply some strategy for the problematic dependency (com.google.code.findbugs:jsr305) and it will resolve the problem around the project, using some version of this dependency. Basically it will align the versions of this library inside the whole project.
There is an answer from #Santhosh (and couple of other people) who suggests to exclude the same dependency for espresso, which should work by the same way, but if the project has some other dependencies who depend on the same library (com.google.code.findbugs:jsr305), again we will have the same issue. So in order to use this approach you will need to exclude the same group from all project dependencies, who depend on com.google.code.findbugs:jsr305. I personally found that Espresso Contrib and Espresso Intents also use com.google.code.findbugs:jsr305.
I hope this thoughts will help somebody to realise what exactly is happening here and how things work (not just copy paste some code) :).
Add this this to dependencies to force using latest version of findbugs library:
compile 'com.google.code.findbugs:jsr305:2.0.1'
delete espresso dependencies in gradle file works for me.
delete those lines in app gradle file:
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
i was trying to use airbnb deeplink dispatch and got this error. i had to also exlude the findbugs group from the annotationProcessor.
//airBnb
compile ('com.airbnb:deeplinkdispatch:3.1.1'){
exclude group:'com.google.code.findbugs'
}
annotationProcessor ('com.airbnb:deeplinkdispatch-processor:3.1.1'){
exclude group:'com.google.code.findbugs'
}
Those who are getting same error in Android 3.0.1,can resolve it by simply update the versions of compileSdkVersion and targetSdkVersion to 27 and also Implement com.android.support:appcompat-v7:27.1.1' in dependencies.
In project ':app' you can add the following to your app/build.gradle file :
android {
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
}
For react-native-firebase, adding this to app/build.gradle dependencies section made it work for me:
implementation('com.squareup.okhttp3:okhttp:3.12.1') { force = true }
implementation('com.squareup.okio:okio:1.15.0') { force = true }
implementation('com.google.code.findbugs:jsr305:3.0.2') { force = true}
REACT NATIVE
If you looking for react native solution, then write this snippet in your affected node_modules gradle build file, e.g. firebase in my case.
android {
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.0'
}
}
I've added a new library module to existing application module in Android Studio. The main difference was adding RxJava 2 and Retrofit 2.
After updating build.gradle of new module I started to get next error:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForBetaNewApiDebug'.
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files
copied in APK META-INF/rxjava.properties File1:
C:\Users\Gaket.gradle\caches\modules-2\files-2.1\io.reactivex.rxjava2\rxjava\2.0.2\cfccdd18cdfbe7b4773d42c9f3512eeafbe5cbf9\rxjava-2.0.2.jar
File2:
C:\Users\Gaket.gradle\caches\modules-2\files-2.1\io.reactivex\rxjava\1.1.5\ece7b5d0870e66d8226dab6dcf47a2b12afff061\rxjava-1.1.5.jar
I see that there is some problem with RxJava (I want to try RxJava 2 and here I see both RxJava 1 and RxJava 2). The problem arises right after adding all dependencies, we do not use RxJava in our main application.
Update:
As I mentioned below, I checked three topics (you can see it below). This issue: possible duplicate is similar to the one that I already mention below: this one. Both of them have workarounds that do not take into account the real problem that I underlined in my answer. And the answer is "There is no production-ready adapter from Retrofit 2 to RxJava 2 at the moment" (full details described in answer below).
I checked several topics: first is some concrete solution for a concrete problem, second talks about rxbindings, but I don't use them, some others also have not resolved my problem or look like total workarounds this one. I tried to google "rxjava 2 and retrofit 2" but haven't found a solution.
Here is the build.gradle of library:
apply plugin: 'com.android.library'
apply plugin: 'com.jakewharton.butterknife'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "com.android.support:appcompat-v7:$supportLibraryVersion"
compile "com.android.support:recyclerview-v7:$supportLibraryVersion"
compile 'io.reactivex.rxjava2:rxjava:2.0.2'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.squareup.okhttp3:okhttp:3.5.0'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile "com.makeramen:roundedimageview:1.3.0"
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
provided 'javax.annotation:jsr250-api:1.0'
compile 'com.jakewharton:butterknife:8.4.0'
testCompile 'junit:junit:4.12'
}
The question is:
Why does this problem happen and what is the proper way to handle it?
You should use the official adapter for the second version of RxJava:
compile 'com.squareup.retrofit2:adapter-rxjava2:2.2.0 // works with RxJava 2
The fact that adapter has version 2.*.* does not mean that it is intended for use with RxJava 2, as I thought.
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0' // won't work with RxJava 2
Previously, you should use a temporary version: Here is the repository of Jake Wharton with Retrofit 2 to RxJava 2 adapter.
I found this problem using command gradlew :app dependencies in Android Studio terminal, where the app is name of my library module. There I looked for "rxjava" keyword and found different versions of it.
Update:
On February, 21 Square published the official version of adapter, as Darshan Mistry pointed out in a comment. Answer updated.
Need to remove duplicate library from the project if added multiple times with different version.
or if two libraries which are dependent and have different version thn both will have different meta inf version which will cause this type of issue.
How to check Dependency/hierarchy
Refere this answer
In your case there are multiple rxjava.properties in jar meta inf
So to ignore that duplicate entry exclude it from the application's build.gradle in android tag
packagingOptions {
exclude 'META-INF/rxjava.properties'
}
What does this error message mean? I don't have duplicated packages in my project
Error:Execution failed for task ':SimpleReader:processDebugResources'.
Error: more than one library with package name 'com.google.android.gms'
You can temporarily disable this error with
android.enforceUniquePackageName=false However, this is temporary and
will be enforced in 1.0
My build.gradle looks like this:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.1'
}
}
apply plugin: 'android'
android {
buildToolsVersion '19.0.3'
defaultConfig {
minSdkVersion 14
targetSdkVersion 17
}
compileSdkVersion 17
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
buildTypes {
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.1'
compile 'com.google.android.gms:play-services:4.2.42'
compile files('libs/gson-2.2.4.jar')
compile files('libs/httpmime-4.1.jar')
compile files('libs/httpclient-4.1.1.jar')
compile files('libs/jsoup-1.7.3.jar')
compile project(':libraries:actionbarsherlock')
compile project(':libraries:sherlocknavigationdrawer')
compile project(':libraries:googleplayservices')
compile project(':libraries:androidslidinguppanel')
compile files('libs/protocol-1.0.4.jar')
compile files('libs/sentry-0.1.4.jar')
compile files('libs/commons-lang-2.3.jar')
}
In my case, the problem was because I was including:
compile 'com.google.android.gms:play-services-wearable:+'
compile 'com.google.android.gms:play-services:4.4.52'
both the wearable play services, and the regular.
I commented out the wearable part, and it works.
Not sure if I'll need it, but it was included by default by the project wizard
today I met the same problem. I need to use Google Analytics, so I import google analytics lib following the tutorial:
compile 'com.google.android.gms:play-services-analytics:9.0.0'
then compile the project, gradle tell me Error: more than one library with package name 'com.google.android.gms'
I can definitely sure that I only directly import com.google.android.gms one time by google analytics lib.
so I navigate to Project tab in Android Studio to see what are the libs this project depend on, then I found play-services-6.5.87 display in External Libraries, like following screenshot:
so now I know there is another lib depend on play-services-6.5.87, but I don't which lib it is.
then I use a gradle command in console to see the project dependencies:
$ ./gradlew -q app:dependencies
the result tells me that com.facebook.android:audience-network-sdk:4.6.0 depend on it.
so how we fix this problem, two way:
if you don't need this audience-network-sdk, just remove it. my project in fact doesn't need it.
if you also need audience-network-sdk and google-analytics, use exclude group grammar, like following snippet code.
//facebook SDK
compile ('com.facebook.android:audience-network-sdk:4.6.0')
{exclude group: 'com.google.android.gms'}
// google analytics
compile 'com.google.android.gms:play-services-analytics:9.0.0'
in your case, the audience-network-sdk can be any other lib that depends on same lib with other libs. here is just a thinking of how to resolve similar problems.
Try removing compile project(':libraries:googleplayservices') or compile 'com.google.android.gms:play-services:4.2.42'. I am pretty sure they are the same library.
I faced similar issue, i got it resolved by following steps:
ionic platform rm android
ionic platform add android
ionic build android
this is a problem with versions. if you have multiple dependencies of same package path ensure the versions are the same
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
I had confused with this problem for a long time.My issue is little different with the question though same error log. I want my sublib's buildtype same with my application's buildtype. So I assigned the buildtype for sublib as the document tells me.
[Gradle Plugin User Guide][1]
This the error I got.
processing flavorCustomResource
Error: more than one library with com.xxx.libCommon
This is my structure. lib1 and lib2 are independent of each other.
app
-> lib1 -> libCommon
-> lib2 -> libCommon
I got the error only when I build my custom buildtype.However, The release version was Ok.
More details. some parts of my build.gradle
app:
android {
buildTypes {
release{}
custom{}
}
}
configurations {
flavorReleaseCompile
flavorCustomCompile
}
dependencies{
compile project(':lib1')
flavorReleaseCompile project(path: ':lib2', configuration: ':release')
flavorCustomCompile project(path: ':lib2', configuration: ':custom')
}
lib1:
android {
publishNonDefault true
buildTypes {
release{}
custom{}
}
}
dependencies{
releaseCompile project(path: ':libCommon', configuration: ':release')
customCompile project(path: ':libCommon', configuration: ':custom')
}
lib2
dependencies {
compile project(':libCommon')
}
Solution: configure the lib2 as lib1. the problem will be solved.
lib2:
android {
publishNonDefault true
buildTypes {
release{}
custom{}
}
}
dependencies{
releaseCompile project(path: ':libCommon', configuration: ':release')
customCompile project(path: ':libCommon', configuration: ':custom')
}
Reason
The problem is something about Library Publication
The default publish is release. if lib2 is not configured, it will use the default publish libCommon(release version) which is different from lib1 -> libCommon(custom version) assigned by lib1's build.gradle.This comes the error.
I wish my post will help someone struggle with the same issue or give some hint to him/her.