I created Google Cloud endpoint library and follow the instructions from Calling Google Apis from Android
But I'm not able to use my endpoints. I created a new project in Android Studio
and copy all the dependencies in gradle.build But When I run the project I see following errors.
Java Compiler:
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Failed to process C:\Users\DELL\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\22.0\3564ef3803de51fb0530a8377ec6100b33b0d073\guava-22.0.jar
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Error while dexing.
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
Caused by: com.android.tools.r8.utils.AbortException
Android Issue:
Default interface methods are only supported starting with Android N (--min-api 24): java.util.Collection com.google.common.collect.BiMap.values()
Message{kind=ERROR, text=Default interface methods are only supported starting with Android N (--min-api 24): java.util.Collection com.google.common.collect.BiMap.values(), sources=[Unknown source file], tool name=Optional.of(D8)}
Default interface methods are only supported starting with Android N (--min-api 24): boolean com.google.common.base.Predicate.test(java.lang.Object)
Message{kind=ERROR, text=Default interface methods are only supported starting with Android N (--min-api 24): boolean com.google.common.base.Predicate.test(java.lang.Object), sources=[Unknown source file], tool name=Optional.of(D8)}
My MainActivity.java is empty right now.
Here is my gradle.build
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.azeem.endpointtest"
minSdkVersion 15
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'
}
}
}
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.0'
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'
// Add the Google API client library.
implementation(group: 'com.google.api-client', name: 'google-api-client', version: '1.21.0') {
// Exclude artifacts that the Android SDK/Runtime provides.
exclude(group: 'xpp3', module: 'xpp3')
exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
exclude(group: 'junit', module: 'junit')
exclude(group: 'com.google.android', module: 'android')
}
// Add the Android extensions for the Google API client library.
// This will automatically include play services as long as you have download that library
// from the Android SDK manager.
// Add the Android extensions for the Google API client library.
implementation(group: 'com.google.api-client', name: 'google-api-client-android',
version: '1.21.0')
{
// Exclude play services, since we're not using this yet.
exclude(group: 'com.google.android.gms:play-services', module: 'google-play-services')
}
// END Google APIs
// The following client libraries make HTTP/JSON on Android easier.
// Android extensions for Google HTTP Client.
implementation(group: 'com.google.http-client', name: 'google-http-client-android',
version: '1.21.0') {
exclude(group: 'com.google.android', module: 'android')
}
// This is used by the Google HTTP client library.
implementation(group: 'com.google.guava', name: 'guava', version: '22.0')
implementation files('libs/endpointapi-v1-1.23.0-SNAPSHOT.jar')
}
In my whole Api I don't need to make any authenticated calls So, please let me know what library is not required so I removed. I want to implement mini library that are necessary. And please let me know why I'm facing this error.
I found it myself, Only two dependencies are required for this.
One is google-api-client-android and the other is Your_endpoint_lib
implementation 'com.google.api-client:google-api-client-android:1.23.0';
implementation files('libs/endpointapi-v1-1.23.0-SNAPSHOT.jar')
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'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].
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'
}
}
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\xxx\AppData\Local\Android\sdk\build-tools\21.1.2\dx.bat --dex --no-optimize --multi-dex --main-dex-list C:\___\android\GooglePlus_1\app\build\intermediates\multi-dex\debug\maindexlist.txt --output C:\___\android\GooglePlus_1\app\build\intermediates\dex\debug --input-list=C:\___\android\GooglePlus_1\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
3
UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError: Java heap space
at com.android.dx.dex.code.RopTranslator.outputBlock(RopTranslator.java:253)
at com.android.dx.dex.code.RopTranslator.outputInstructions(RopTranslator.java:233)
at com.android.dx.dex.code.RopTranslator.translateAndGetResult(RopTranslator.java:212)
at com.android.dx.dex.code.RopTranslator.translate(RopTranslator.java:105)
at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:317)
at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:137)
at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:93)
at com.android.dx.command.dexer.Main.processClass(Main.java:729)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.command.dexer.Main.access$300(Main.java:83)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:505)
at com.android.dx.command.dexer.Main.runMultiDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:244)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
Gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.googleplus_1"
minSdkVersion 10
targetSdkVersion 21
versionCode 1
versionName "1.0"
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:7.0.0'
compile 'com.google.gdata:core:1.47.1'
}
/*
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
all*.exclude group: 'com.google.android.gms', module: 'play-services'
}*/
Why are you adding com.google.gdata:core:1.47.1?
If you read on it's official site: http://code.google.com/p/gdata-java-client/, it says:
Android support: If you are developing for Android and the Google API you want to use is included in the Google Play Services library,
you should use that library for the best performance and experience.
If the Google API you want to use with Android is not part of the
Google Play Services library, you can use the Google APIs Client
Library for Java, which supports Android 1.5 (or higher) and provides
other features such as OAuth 2.0 and Maven.
It suggests you use:
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.api-client:google-api-client:1.18.0-rc'
}
Very important for Google Play Services, do not use the "whole" dependency directly:
dependencies {
compile 'com.google.android.gms:play-services:7.0.0'
}
Do pick individual modules that you need:
dependencies {
# Google+
com.google.android.gms:play-services-plus:7.0.0
# Google Account Login
com.google.android.gms:play-services-identity:7.0.0
# Google Actions, Base Client Library
com.google.android.gms:play-services-base:7.0.0
# Google App Indexing
com.google.android.gms:play-services-appindexing:7.0.0
# Google Analytics
com.google.android.gms:play-services-analytics:7.0.0
# Google Cast
com.google.android.gms:play-services-cast:7.0.0
# Google Cloud Messaging
com.google.android.gms:play-services-gcm:7.0.0
# Google Drive
com.google.android.gms:play-services-drive:7.0.0
# Google Fit
com.google.android.gms:play-services-fitness:7.0.0
# Google Location, Activity Recognition, and Places
com.google.android.gms:play-services-location:7.0.0
# Google Maps
com.google.android.gms:play-services-maps:7.0.0
# Google Mobile Ads
com.google.android.gms:play-services-ads:7.0.0
# Google Nearby
com.google.android.gms:play-services-nearby:7.0.0
# Google Panorama Viewer
com.google.android.gms:play-services-panorama:7.0.0
# Google Play Game services
com.google.android.gms:play-services-games:7.0.0
# SafetyNet
com.google.android.gms:play-services-safetynet:7.0.0
# Google Wallet
com.google.android.gms:play-services-wallet:7.0.0
# Android Wear
com.google.android.gms:play-services-wearable:7.0.0
}
Source: http://developer.android.com/google/play-services/setup.html