I've been working on a Firebase-based social app for a while. The app was coming along fine, when I noticed everybody (except for me) kept getting inexplicable crashes. I assumed it was because the app was built around open source code, so I started anew from scratch. Again, the app was coming along fine, but as soon as I published it, similar inexplicable crashes started occuring. At this point I realised the crashes only occured in the release APK. As far as I can see, all of these crashes are related to Firebase. Most of them are NullPointerExceptions where some data is Null in the release APK, but not Null in the test version with the exact same use case.
I managed to solve one of these mysterious crashes by correctly implementing multidex (I didn't implement this correctly before and I think this caused one of the problems). Problems still remain though. I've completely turned of ProGuard, because I suspect that may be one of the problems. ProGuard was disabled before, but now I added these lines, just to be sure:
-dontoptimize
-dontshrink
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
Still crashes.
This is becoming a bit of a problem. What could possibly solve this problem?
Here's my Build.gradle.
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "app.id"
minSdkVersion 16
targetSdkVersion 25
versionCode 16
versionName "0.0.16"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
renderscriptTargetApi 24
renderscriptSupportModeEnabled true
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services:11.0.1'
compile 'com.google.firebase:firebase-messaging:11.0.1'
compile 'com.google.firebase:firebase-auth:11.0.1'
compile 'com.google.firebase:firebase-database:11.0.1'
compile 'com.google.firebase:firebase-storage:11.0.1'
compile 'com.firebaseui:firebase-ui-auth:2.0.1'
[loads more dependencies]
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
}
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'com.google.gms.google-services'
The problem has gone away on a fresh project. Here's the things I've done to avoid this.
Switched to Android Studio 3.0 (Canary 7), including the new build tools
Switched to Kotlin as my main project language
Made sure my project's build.gradle gave no error notifications about different versions (using the project files view). Firebase UI caused one of these errors.
Avoided MultiDex alltogether
Either one of these may have solved the problem. I'm not sure how long I can avoid using multidex, but I'll update this answer if I find out MultiDex is the problem and / or find an alternative solution.
Related
I'm curious about this. I made an Android program using an earlier version of the Google Android Studio (I believe 2.3.x), and recently upgraded to a newer version that came out (3.1.2), however, when I tried to bring in the program directly to this version and fire it up, I got a lot of compile errors due to various things being out of date. I tried to fix these in a rather ad-hoc manner because I could not find any comprehensive information despite much googling detailing how to properly migrate a project and it seemed to work (and so I can't post what they were), but now it seems to have broken again (perhaps because of another automatic upgrade) and I am getting this, for which searching has not yielded anything helpful:
Could not find recyclerview-v7.jar (com.android.support:recyclerview-v7:27.1.1).
Searched in the following locations:
https://jcenter.bintray.com/com/android/support/recyclerview-v7/27.1.1/recyclerview-v7-27.1.1.jar
Please install the Android Support Repository from the Android SDK Manager.
Open Android SDK Manager
Yet I go to the "Android SDK Manager" (that shows as a link in the output) and it says the relevant package is both installed and apparently at its latest version (since it does not say any updates are available). Moreover I was not aware I was even using the control "recyclerview" in the program, so I am rather puzzled as to why I am getting this error and I suspect it is because I did the migration wrong (not surprising due to the frustrating lack of information). I still have the project original from the earlier version so I could repeat it, but I'd like to then know how to do it correctly as I suspect this is resulting from the fact that I don't really know what I'm doing - and so what is the way to do that?
FWIW, the present project build.gradle is
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "sg.simetricclock.kumari.metricclock"
minSdkVersion 18
targetSdkVersion 25
versionCode 2
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:design:27.1.1'
testCompile 'junit:junit:4.12'
}
repositories {
maven {
url 'https://maven.google.com'
}
}
dependencies {
compile 'com.android.support.constraint:constraint-layout:2.0.0-alpha1'
}
dependencies {
compile 'com.android.support.constraint:constraint-layout:+'
}
First Change Your Compile statement to Implimentation and Then Change Your Targeted SDK Version 28 And Then SYNC Your Project. I Hope After That You Will Not get Error
After adding Android Facebook SDK dependencies
compile 'com.facebook.android:facebook-android-sdk:4.21.0'
I'm getting error in
compile 'com.android.support:appcompat-v7:25.3.1'
But Project is running fine.
All com.android.support libraries must use the exact same version
specification (mixing versions can lead to runtime crashes). Found
versions 25.3.1, 25.0.0. Examples include
com.android.support:animated-vector-drawable:25.3.1 and
com.android.support:cardview-v7:25.0.0 less... (Ctrl+F1)
There are some combinations of libraries, or tools and libraries, that
are incompatible, or can lead to bugs. One such incompatibility is
compiling with a version of the Android support libraries that is not
the latest version (or in particular, a version lower than your
targetSdkVersion.)
Build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
repositories {
mavenCentral()
}
defaultConfig {
applicationId "sujeet.raj.com"
minSdkVersion 15
targetSdkVersion 25
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:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.facebook.android:facebook-android-sdk:4.21.0'
}
This problem occurs due to different version of dependency files get downloaded.
Explicitly put this as well in gradle file and sync again.
compile 'com.android.support:animated-vector-drawable:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
Under this directory you can find these libraries getting downloaded
Project Files/Your project/.idea/libraries
Don't ask me why but this solved it for me:
android {
/.../
configurations.all {
resolutionStrategy.force 'com.android.support:cardview-v7:27.1.0'
resolutionStrategy.force 'com.android.support:animated-verctor-drawable:27.1.0'
resolutionStrategy.force 'com.android.support:customtabs:27.1.0'
resolutionStrategy.force 'com.google.android.gms:play-services-base:12.0.1'
resolutionStrategy.force 'com.google.android.gms:play-services-auth:12.0.1'
}
}
You can solve this with one of the following solutions: original here
Run a Gradle dependency report to see what your full tree of dependencies is. From there, you will see which one of your libraries is asking for a different version of the Android Support libraries. For whatever it is asking for, you can ask for it directly with the 25.2.0 version, or use Gradle's other conflict resolution approaches to arrange to get the same version.
Run:
./gradlew -q dependencies <module-name>:dependencies --configuration compile
Example:
./gradlew -q dependencies app:dependencies --configuration compile
For me, the error disappeared after removing com.google.android.gms:play-services:10.2.0
And only include com.google.android.gms:play-services-location:10.2.0 and com.google.android.gms:play-services-maps:10.2.0 as they are the only two play services that I use.
I think the gms:play-services depend on some old components of the support library, so we need to add them explicitly ourselves.
Maybe I am too late for this, but well, trying to be helpful here... this is how I solve it.
open
project/your project/.idea/libraries
then head to facebook sdk and you can see this
library name="facebook-android-sdk-4.22.1"
use the number "4.22.1" into the one in build.gradle
this is how I do it, I am too a beginner myself.
In my project, I have used libraries which require multidex support. Based on the research I did, I came to know that it causes delay during app start up.
I have enabled multidex feature in gradle. defaultConfig { multiDexEnabled true }
I used to get NoClassDefFound Exception for kitkat devices so I added the following:
I have added application name in manifest as
android:name="android.support.multidex.MultiDexApplication"
and extended my application class with MultiDexApplication.
I know any one of the above is sufficient but I have just written both.
I tried different ways to optimize the duration of start up like the following :
1.added productFlavors {
dev {
minSdkVersion 21
}
prod {
minSdkVersion 14
}
}
dexOptions {
preDexLibraries false
javaMaxHeapSize "4g"
}
I imported only required google play service's libraries instead of importing full library.
Can you please suggest me an approach to improvise the duration because its actually taking more than 10 seconds and some times even more than that in some of the devices?
Or Is there any other reason that might be causing the delay apart from multidex?
Thanks in advance.
I have added my build.gradle file contents :
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.example.app"
minSdkVersion 17
targetSdkVersion 23
versionCode 3
versionName "1.2"
multiDexEnabled true
}
dexOptions {
incremental true
javaMaxHeapSize "10g"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/ormlite-android-4.28.jar')
compile files('libs/ormlite-core-4.28.jar')
compile project(':volley')
compile 'com.android.support:cardview-v7:23.2.1'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.siyamed:android-shape-imageview:0.9.+#aar'
compile 'com.viewpagerindicator:library:2.4.1#aar'
compile 'com.android.support:design:23.2.1'
compile 'com.facebook.android:facebook-android-sdk:4.1.2'
compile 'org.jsoup:jsoup:1.8.2'
compile 'org.twitter4j:twitter4j:4.0.3'
compile 'com.github.castorflex.smoothprogressbar:library-circular:1.1.0'
compile 'com.orhanobut:dialogplus:1.11#aar'
compile 'com.google.android.gms:play-services-maps:8.3.0'
compile 'co m.google.android.gms:play-services-gcm:8.3.0'
compile 'com.google.android.gms:play-services-location:8.3.0'
compile 'org.java-websocket:Java-WebSocket:1.3.0'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
}
There is a strange issue with newly released Android Studio 2.0 or 2.1. First time of launching application take longer than usual. This issue happens only in debug mode and not effect to your released APK. Also I was suffering this issue and found this solution.
Settings/Preferences(Mac) → Build, Execution, Deployment → Instant Run and uncheck Instant Run
This will solve your problem and if it is please mark as accepted answer.
There is an issue in version 2.0 and 2.1 of android studio, but the answer is simple. You must go to
Preferences/Build, Execution, Deployment/Instant Run.
Then when you click on "Instant Run" in the right side will appear 4 options with a checkbox for echa one, you must uncheck the first and the last one.
Finally click Apply,Ok.
And that's all.
That will solve the problem
Verdant newbie here. I'm making a fairly simple project that needs to be compatible with Android versions older than Lollipop, but still want to have the app look nicer by using AppCompat.
Unfortunately, I do not know how to work (or even find) the gradle - I tried to run a gradle task: compile "com.android.support:appcompat-v7:21.0.+"
But it returned an error saying that "Task 'compile' is ambiguous...." in my project.
Could anyone tell me how to add this? I've searched all over Google, but everything goes way over my head.
Thanks!
Have you been able to locate Gradle file?
Edit your gradle like this :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.xyz.xyz"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.00.00"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
}
Update your question and post full Gradle code.
Add the appcomapt library(com.android.support:appcompat-v7:21.0.+") in dependancy section of the build.gradle file
Or second way to add library is by searching on maven repo.this can be done by traversing file->project structure->app>dependancy->click (+) ->add Library dependancy
Task 'compile' is ambiguous.
This issue is not the Compile Issue. but this was an issue on the task itself.
if you are not using a command like "gradle compileDebug" then one of the android configurations are executing the task and it is not working well with your build.gradle.
Here is a link that seems to relate specifically to your issue. Click Here
I'm building an Android library for music streaming. It has ExoPlayer as dependency (excellent library btw!).
We use this library for another project that we're also developing right now, in Xamarin. Currently, we need to add both libraries (my .aar and a .jar for ExoPlayer). That's a bit annoying to be honest, I'd love to just drop my .aar in, and go.
So two questions:
is there a way I can bundle the ExoPlayer inside my .aar, using gradle and stuff? (I'm quite a beginner here, be thorough please)
I realise it might not be the best thing to do (dependency should be managed by app, blah blah blah), but really we will always test ExoPlayer and my lib together every time we update the former. So is there a strong reason I should not bundle ExoPlayer in my lib, or is that ok?
And here's my current gradle file. Nothing exciting to look at though. But as I converted the initial app to a lib, maybe there's something odd, who knows...
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ('com.google.android.exoplayer:exoplayer:r1.5.6')
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
compile 'com.android.support:appcompat-v7:23.2.0'
}
There are no solutions for this until this issue is solved, but a viable alternative for someone can be to bundle the .aar(s) singularly using the "Import .JAR/.AAR Package" while clicking on "New Module".
The only problem with this approach is that you can bundle only 1 AAR at a time in this way, so you need to create a module for each one of them.
In alternative you can try with Kezong fat aar library:
https://github.com/kezong/fat-aar-android