Android dependency issue - ApachePOI & fasterxml - android

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.

Related

Generated Signed Bundle / APK - Lint found fatal errors while assembling a release target

I'm trying to generate a signed apk but I've got the following error:
Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint or modify your build script as follows:
...
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
...
So I started looking at how to fix the problem and hit the head against this question and I've found some useful information.
In practice, there is a file located in ..\app\build\reports\ named \lint-results-release-fatal.html
containing the reason for the error:
Duplicate Platform Classes
../../build.gradle: commons-logging 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.
../../build.gradle: `httpclient` 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.
Sorry if the reading can be boring but I'm trying to explain step by step...
So I kept looking until I got stuck following this question. Basically the advice is to add these two lines of code to exclude duplicate classes:
configurations {
all {
exclude module: 'httpclient'
exclude module: 'commons-logging'
}
}
Unfortunately, there is a problem, when I go to compile the app again I get this error that I can't solve:
error: cannot access ContentType
class file for org.apache.http.entity.ContentType not found
I really think that the exclusion of the httpclient module and the error reported above are linked, but I could be wrong...
These are some useful information:
Android Studio 3.5.1
Build #AI-191.8026.42.35.5900203, built on September 25, 2019
JRE: 1.8.0_202-release-1483-b03 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
Thanks again for reading up to here and if you have a solution or a suggestion are welcome!
14:54 05/11/19
Add other information that may give you a better overview of the situation
compileSdkVersion 28
defaultConfig {
applicationId "com.example.app"
minSdkVersion 22
targetSdkVersion 28
versionCode 2
versionName "21.19.08.27"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
16:35 05/11/2019
Here there are the dependencies
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.recyclerview:recyclerview-selection:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0-alpha07'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.williamww:silky-signature:0.1.0'
implementation 'com.afollestad.material-dialogs:core:0.9.1.0'
implementation 'com.weiwangcn.betterspinner:library-material:1.1.0'
implementation 'com.weiwangcn.betterspinner:library:1.1.0'
implementation 'org.apache.httpcomponents:httpmime:4.3.6'
implementation 'com.ajts.androidmads.sqliteimpex:library:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
10:14 08/11/2019
Previusly i didn't mention the utilize of useLibrary 'org.apache.http.legacy'
10:22 11/11/2019
I've created a replica of the error i'm getting on the following github project.
So my goal is to be able to compile and use the following classes:
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.InputStreamBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
Disabling Lint is not a solution; better remove the duplicate dependency altogether:
implementation "org.apache.httpcomponents:httpmime:4.3.6"
and instead provide it in the expected way (the "legacy" applies since Android API level >= 23):
useLibrary "org.apache.http.legacy"
See behavior changes... alternatively, just use HttpURLConnection, OkHttp or Retrofit.
org.apache.httpcomponents could also be used - but not both packages at the same time.
One quick & dirty workaround, in order to keep the imports exactly the same, would be:
implementation "org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2"
Add this in app level gradle
buildTypes {
lintOptions {
checkReleaseBuilds false
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
check your dependencies, sometimes the problem is the library version. the update library version is able to reduce your problem build apk in Android
android {
lintOptions {
checkReleaseBuilds fals
abortOnError false
}
}
Adding this in your App level gradle will fix the error, but later you need to find it and fix the error because lint is there for a reason.
This will fix the
if your want to find out the exact error then go to following path in your project
/app/build/reports/lint-results-release-fatal.html or
/app/build/reports/lint-results-release-fatal.xml
otherwise you can use
lintOptions {
checkReleaseBuilds false
abortOnError false
}
A heartfelt thanks to everyone who answered to the question.
Removing the Lint controls is never a good solution and a big thanks to Martin Zeitler I was able to solve the problem.
In practice, modifying the dependencies I managed to solve it:
useLibrary 'org.apache.http.legacy'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.recyclerview:recyclerview-selection:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0-alpha07'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.williamww:silky-signature:0.1.0'
implementation 'com.afollestad.material-dialogs:core:0.9.1.0'
implementation 'com.weiwangcn.betterspinner:library-material:1.1.0'
implementation 'com.weiwangcn.betterspinner:library:1.1.0'
implementation 'org.apache.httpcomponents:httpclient-android:4.3.5'
implementation('org.apache.httpcomponents:httpmime:4.3.6') {
exclude module: 'httpclient'
}
implementation 'com.ajts.androidmads.sqliteimpex:library:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
The differences between the question and the solutions are the following:
implementation 'org.apache.httpcomponents:httpclient-android:4.3.5'
implementation('org.apache.httpcomponents:httpmime:4.3.6') {
exclude module: 'httpclient'
}

NoClassDefFoundError: android.app.PictureInPictureParams

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].

Using Dagger 2.11 with kotlin in android [duplicate]

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'
}
}

Using RxJava 2 and Retrofit 2, adapter version issue

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'
}

GCM Error - googleCloudMessaging.register

I have the problem that the android application says. "The application xxxx Sorry stopped" to work with the push notificaction, when performing the debugger that happens when it passes:
method 1
InstanceID InstanceId = InstanceID.getInstance (context);
token = instanceID.getToken (key_id.toString ()
GoogleCloudMessaging.INSTANCE_ID_SCOPE); getToken error,
method 2
Both an the same mistake
if (googleCloudMessaging == null) {
googleCloudMessaging = GoogleCloudMessaging.getInstance(context);
}
token = googleCloudMessaging.register(key_id);
note that the token is generated but the application is closed, error:
"The method 'java.io.File android.support.v4.content.ContextCompat.getNoBackupFilesDir (android.content.Context)' was expected to be of type virtual but was found to be Instead of direct type (declaration of 'java.lang .reflect.ArtMethod 'appears in /system/framework/core-libart.jar)"
I am using android studio, for
cdvCompileSdkVersion = android-22
cdvBuildToolsVersion = 22.0.1
Error:
"FATAL EXCEPTION: main
Process: PID: 11989
java.lang.IncompatibleClassChangeError: The method 'java.io.File android.support.v4.content.ContextCompat.getNoBackupFilesDir(android.content.Context)' was expected to be of type virtual but instead was found to be of type direct (declaration of 'java.lang.reflect.ArtMethod' appears in /system/framework/core-libart.jar)
at com.google.android.gms.iid.zzd.zzde(Unknown Source)
at com.google.android.gms.iid.zzd.<init>(Unknown Source)
at com.google.android.gms.iid.zzd.<init>(Unknown Source)
at com.google.android.gms.iid.InstanceID.zza(Unknown Source)
at com.google.android.gms.iid.InstanceID.getInstance(Unknown Source)
at com.google.android.gms.iid.InstanceIDListenerService.zzn(Unknown Source)
at com.google.android.gms.iid.InstanceIDListenerService.onStartCommand(Unknown Source)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2924)
at android.app.ActivityThread.access$2100(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1415)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)"
What could be the problem?
Regards,
Google has updated on their release note that this issue is fixed, you just have to update the version to 9.0.2
Here is the release note: https://developers.google.com/android/guides/releases
The issue you are experiencing is due to an incompatibility between
play-services / firebase sdk v9.0.0 and com.android.support:appcompat-v7 >= 24
It's possible that you are not depending directly from appcompat-v7 >= 24 but some other dependencies are configured to use the most updated appcompat available.
To fix this issue we just released play-services / firebase sdk version 9.0.1
This minor release should fix the incompatibility with appcompat-v7 !
I also facing same error.
SOLUTION
Just paste this in your gradle file
configurations.all {
resolutionStrategy {
force 'com.android.support:design:23.4.0'
force 'com.android.support:support-v4:23.4.0'
force 'com.android.support:appcompat-v7:23.4.0'
}
}
This issue is that you have dependencies that include old versions of the support library. CHECK THIS LINK
Here is my gradle file check this
gradle
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias 'hwindi'
keyPassword '123456'
storeFile file('D:/Company Projects/Hwindi/Project 2/Play_KeyStore/HwindiKeyStore.jks')
storePassword '123456'
}
}
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.hwindiapp.passenger"
minSdkVersion 16
targetSdkVersion 23
versionCode 7
versionName "1.6"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'lib/arm64-v8a/libcardioDecider.so'
exclude 'lib/arm64-v8a/libcardioRecognizer.so'
exclude 'lib/arm64-v8a/libcardioRecognizer_tegra2.so'
exclude 'lib/arm64-v8a/libopencv_core.so'
exclude 'lib/arm64-v8a/libopencv_imgproc.so'
exclude 'lib/armeabi/libcardioDecider.so'
exclude 'lib/armeabi-v7a/libcardioDecider.so'
exclude 'lib/armeabi-v7a/libcardioRecognizer.so'
exclude 'lib/armeabi-v7a/libcardioRecognizer_tegra2.so'
exclude 'lib/armeabi-v7a/libopencv_core.so'
exclude 'lib/armeabi-v7a/libopencv_imgproc.so'
exclude 'lib/mips/libcardioDecider.so'
exclude 'lib/x86/libcardioDecider.so'
exclude 'lib/x86/libcardioRecognizer.so'
exclude 'lib/x86/libcardioRecognizer_tegra2.so'
exclude 'lib/x86/libopencv_core.so'
exclude 'lib/x86/libopencv_imgproc.so'
exclude 'lib/x86_64/libcardioDecider.so'
exclude 'lib/x86_64/libcardioRecognizer.so'
exclude 'lib/x86_64/libcardioRecognizer_tegra2.so'
exclude 'lib/x86_64/libopencv_core.so'
exclude 'lib/x86_64/libopencv_imgproc.so'
}
configurations.all {
resolutionStrategy {
force 'com.android.support:design:23.4.0'
force 'com.android.support:support-v4:23.4.0'
force 'com.android.support:appcompat-v7:23.4.0'
}
}
}
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1+'
compile 'com.google.android.gms:play-services-gcm:9.0.0'
compile 'com.google.android.gms:play-services-location:9.0.0'
compile 'com.google.android.gms:play-services-maps:9.0.0'
compile 'com.google.android.gms:play-services-plus:9.0.0'
compile 'com.facebook.android:facebook-android-sdk:4+'
compile 'com.paypal.sdk:paypal-android-sdk:2.13.3'
compile 'com.wdullaer:materialdatetimepicker:2.2.0'
compile 'com.mukesh:permissions:1.0.3'
}
As far as I have read, java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist error, which you encountered after migrating a GCM Client App for Android to Firebase Cloud Messaging, were also encountered by many developers after adding the dependency for Crash Reporting to project-level build.gradle file:
compile 'com.google.firebase:firebase-crash:9.0.0'
So, if you happen to use Firebase Crash Reporting, you must ensure that crash reporting is multi-process safe. Otherwise, it may cause concurrency issues as stated in Report Crashes - Known Issues.
One probable solution that I found is to set Android context and enable Offline Persistence, wherein you enable it via the FirebaseDatabase object in your MainActivity:
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
Sample solution in MainActivity.java:
#Override
public void onCreate() {
super.onCreate();
if (!FirebaseApp.getApps(this).isEmpty()) {
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
}
}
This SO post - java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] helped with my searches. I hope that will help you too.
Finally this problem is solved on v9.0.2. Just update Google Play Service library.
compile 'com.google.android.gms:play-services:9.0.2'
After updating, another error can occur: finished with non-zero exit value 2
Solution for this one is here: Java finished with non-zero exit value 2 - Android Gradle
Solved issue by using below code. Just updated
compileSdkVersion 24
buildToolsVersion "24.0.1"
.
.
.
dependencies
{
compile 'com.android.support:recyclerview-v7:24.1.1'
compile "com.google.android.gms:play-services-gcm:9.4.0"
}
This solved my GCM error.

Categories

Resources