On my latest release a few of my users (less than 0.2%) are getting a crash because android.support.v7.app.AppCompatDelegateImplV23 can not be found. I can not reproduce the issue, I'm only getting reports over crashlytics. I have used apktool to extract the files out of my apk and I can see AppCompatDelegateImplV23.smali in there. Any idea what could be happening?
This is my compile line on gradle:
compile 'com.android.support:appcompat-v7:23+'
This is the exception:
Fatal Exception: java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV23
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:133)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:117)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:456)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at MyActivityClass.onCreate(MyActivityClass.java:353)
at android.app.Activity.performCreate(Activity.java:6248)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1125)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2437)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2544)
at android.app.ActivityThread.access$900(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1394)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:168)
at android.app.ActivityThread.main(ActivityThread.java:5845)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:117)
EDIT: This is my main gradle file:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
jcenter() // version plugin support
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.android.tools.build:gradle:1.3.1'
}
allprojects {
repositories {
jcenter()
}
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
signingConfigs {
config {
......
}
}
compileSdkVersion 23
buildToolsVersion "23.0.1"
useLibrary 'org.apache.http.legacy'
productFlavors {
// Define separate dev and prod product flavors.
dev {
// dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
// to pre-dex each module and produce an APK that can be tested on
// Android Lollipop without time consuming dex merging processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion 14
}
}
defaultConfig {
applicationId "mypackage"
minSdkVersion 14
targetSdkVersion 23
versionCode some number
versionName "some version number"
multiDexEnabled true
signingConfig signingConfigs.config
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent,"myapk.apk")
}
}
}
debug {
signingConfig signingConfigs.config
}
}
repositories {
mavenCentral()
mavenLocal()
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'AndroidManifest.xml'
exclude 'META-INF/beans.xml'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/DEPENDENCIES'
}
productFlavors {
}
dexOptions {
// preDexLibraries = false
jumboMode = true
javaMaxHeapSize "2g"
//doesn't seem to be supported with multidex
// incremental true
}
lintOptions{
disable 'MissingTranslation'
disable 'ExtraTranslation'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//multidex
compile 'com.android.support:multidex:1.0.0'
//support libs
compile 'com.android.support:support-v4:23+'
compile 'com.android.support:appcompat-v7:23+'
compile 'com.android.support:cardview-v7:23+'
compile 'com.android.support:design:23+'
//app invites
compile 'com.google.android.gms:play-services-appinvite:8+'
compile 'com.google.android.gms:play-services-analytics:8+'
//chromecast
compile 'com.google.android.gms:play-services-cast:8+'
compile 'com.android.support:mediarouter-v7:23+'
//plus button
compile 'com.google.android.gms:play-services-plus:8+'
compile('com.crashlytics.sdk.android:crashlytics:2.5.5#aar') {
transitive = true;
}
compile 'com.github.navasmdc:MaterialDesign:1.+#aar'
//material lib needs it
compile 'com.nineoldandroids:library:2.4.+'
compile 'com.facebook.stetho:stetho:1+'
compile 'com.facebook.stetho:stetho-okhttp:1+'
//debugCompile 'com.squareup.leakcanary:leakcanary-android:1+'
debugCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1+'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1+'
compile 'com.makeramen:dragsortadapter:1.3+'
compile 'com.github.amlcurran.showcaseview:library:5.0.0'
}
EDIT: just had a new report but for a different version of the same class
Fatal Exception: java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV14
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:135)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:117)
at android.support.v7.app.AppCompatActivity.getDelegate(AppCompatActivity.java:456)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at MyActivity.onCreate(MyActivity.java:353)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2044)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2105)
at android.app.ActivityThread.access$600(ActivityThread.java:133)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1211)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4795)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(NativeStart.java)
EDIT: I've just gone over a lot of the reports, some are for AppCompatDelegateImplV23 and some are for AppCompatDelegateImplV14, some involved XPosed but most don't. The one thing that is common to all of them is that they are all for rooted phones.
First of all, we need to understand why java.lang.NoClassDefFoundError error occurs :
So the answer is that when there is a class file that your code depends on and it is present at compile time but not found at runtime. Look for differences in your build time and runtime classpaths.
So there are some options by that you can remove this error:
1) Make preDexLibraries to true:
dexOptions {
preDexLibraries = true
jumboMode = true
javaMaxHeapSize "2g"
//doesn't seem to be supported with multi dex
// incremental true
}
2) There may be the problem with the incremental build system. So try to try to remove your build folder from your project and Rebuild the project OR Right click on your project -> "Open module settings" -> Dependencies tab -> check if Export is checked for your library
3) You need to do more than just provide MultiDex support.
multiDexEnabled = true in your defaultConfig block
Include compile 'com.android.support:multidex:1.0.0' in your dependencies
Have your Application class extend MultiDexApplication instead of just Application. Alternatively, you can call MultiDex.install() in attachBaseContext() of your application
For more reference you can check the below link which has provided more advance understanding of multi dex.
https://developer.android.com/tools/building/multidex.html
4) Or at last you can add jar files of V7 into your project's libs folder and then add it your build System.
5) Also try removing the jar files as well as it still includes the com.android.support:support-v4:23+ as gradle has a repository where it downloads the jars delcared like compile 'compile 'com.android.support:appcompat-v7:23+'
Hope this can give you some clue about your error.
My guess is that the problem is due to the xposed framework. At the bottom of the stack trace, you can find that the zygote was started by the xposed framework.
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:117)
This means that the user is using a custom Android rom with the xposed framework installed. The framework is usually used to modify the behavior of the Android framework (and any app of course) code by injecting new code at run-time.
You can check how it works at: https://github.com/rovo89/XposedBridge/tree/art/app/src/main/java/de/robv/android/xposed
Since the code behavior can be altered in various degrees depending on what mods are installed via the xposed framework, I cannot pinpoint the exact cause of your exception. However, if all the stack traces you have got start with the XposedBrigde.main(), then I can say that your problem is due to the exposed framework or the mods installed via the framework.
Related
I developed an app that uses a swagger-generated Java client. The client is in a project called "api", while the app is in a project called "app".
When I build the app via Build/Make Project everything works fine. Also, when I try to run the app on an emulated or physical device Run/Run 'app'. Running with debugger works as well. Even when I build the project via Buid/Generate Signed Bundle/APK and choose the debug option, it works.
Now. The build fails when I try to create a signed release build. The following messages show:
Caused by: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: [...]\app\build\intermediates\transforms\dexBuilder\release\54, [...]\app\build\intermediates\transforms\externalLibsDexMerger\release\0, [...]\app\build\intermediates\transforms\dexBuilder\release\52.jar, [...]\app\build\intermediates\transforms\dexBuilder\release\53.jar
Caused by: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: [...]\app\build\intermediates\transforms\dexBuilder\release\54, [...]\app\build\intermediates\transforms\externalLibsDexMerger\release\0, [...]\app\build\intermediates\transforms\dexBuilder\release\52.jar, [...]\app\build\intermediates\transforms\dexBuilder\release\53.jar
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
Caused by: com.android.tools.r8.utils.AbortException: Error: Program type already present: io.swagger.client.ApiCallback
I am pretty new to developing with Android Studio and Gradle. I tried some solutions on Stack Overflow that already suggested to add some libraries but so far none of them worked with my problem.
To me, its especially suspicious that the last error message points to io.swagger.client.ApiCallback.
Could it have anything to do with the fact that both settings.gradle for "api" and "app" have the same content? Both look like this:
rootProject.name = "swagger-java-client". This is the only line in the file, but as far as I know, the settings.gradle for "app" already hat that content. I cant remember changing it so its odd to me that it shows "swagger-java-client". Is that normal?
Update 1
ProGuard has been mentioned in the comments to might be a problem. This is the only occurrence I could find, referencing it. In my build.gradle for the "app"-project, there is this part:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
However, removing it did not change anything.
Update 2
When searching for "io.swagger" AS only finds this:
When searhing for "io.swagger.client.ApiCallback" AS only finds this:
Update 3
As suggested, I tried adding
android {
defaultConfig {
multiDexEnabled true
}
}
and adding android.enableD8 = false but that didn't help either.
Here are my build.gradle-Files (the first ones that caused the problems, without the suggested corrections I've tried so far.)
build.gradle (Module: api) (generated by Swagger):
apply plugin: 'idea'
apply plugin: 'eclipse'
group = 'io.swagger'
version = '1.0.0'
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
repositories {
jcenter()
}
if(hasProperty('target') && target == 'android') {
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
// Rename the aar correctly
libraryVariants.all { variant ->
variant.outputs.each { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.aar')) {
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
output.outputFile = new File(outputFile.parent, fileName)
}
}
}
dependencies {
provided 'javax.annotation:jsr250-api:1.0'
}
}
afterEvaluate {
android.libraryVariants.all { variant ->
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
task.description = "Create jar artifact for ${variant.name}"
task.dependsOn variant.javaCompile
task.from variant.javaCompile.destinationDir
task.destinationDir = project.file("${project.buildDir}/outputs/jar")
task.archiveName = "${project.name}-${variant.baseName}-${version}.jar"
artifacts.add('archives', task);
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
} else {
apply plugin: 'java'
apply plugin: 'maven'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
install {
repositories.mavenInstaller {
pom.artifactId = 'swagger-java-client'
}
}
task execute(type:JavaExec) {
main = System.getProperty('mainClass')
classpath = sourceSets.main.runtimeClasspath
}
}
dependencies {
compile 'io.swagger:swagger-annotations:1.5.21'
compile 'com.squareup.okhttp:okhttp:2.7.5'
compile 'com.squareup.okhttp:logging-interceptor:2.7.5'
compile 'com.google.code.gson:gson:2.8.2'
compile 'org.threeten:threetenbp:1.3.5'
testCompile 'junit:junit:4.12'
}
build.gradle (Module: app):
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "projectName"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "0.1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:design:28.0.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'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation fileTree(dir: '../api/build/libs', include: ['*.jar'])
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.squareup.okhttp:okhttp:2.7.5'
api project(path: ':api')
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
implementation 'org.jetbrains:annotations-java5:15.0'
}
Here are some workaround :
Can you please make sure you have multiDexEnabled set to true as shown below in your gradle settings:
android {
defaultConfig {
multiDexEnabled true
}
}
Try android.enableD8 = false in grade.properties
Caused by: com.android.tools.r8.utils.AbortException: Error: Program type already present: io.swagger.client.ApiCallback
Means there are multiple dependencies contain this class, maybe different versions, so you need to exclude them.
Press shift twice, search io.swagger, then record the found jar files.
If these jar files are simply duplicated, keep 1 in build.gradle.
If these jar files are modules of other dependency, enter gradlew -q app:dependencies in the terminal, find the root dependency names.
In build.gradle, choose 1 dependency to keep, for others add exclude command.
For example change
implementation 'xxx:xxx'
to
implementation ('xxx:xxx') { exclude module 'module-name-to-be-excluded' }
UPDATE
Some options to try:
Change build variants of both modules to release, then Build\Build APK
If success, copy the text from Gradle Console.
Next Build\Generate Signed APK...
Compare the text in Gradle Console with the above one to check the difference.
I've found the answer to my question:
What I did was to create the swagger client, move the created folder into my project, adjust the settings.gradle file and the build.gradle file accordingly.
What went wrong
The way I configured things, gradle would build the ´api´ project and then the app project.
For some reason, when I configured things as release, the app project referenced the code of the api project, as well as the resulting .jar file. Thats where the Program type already present came from.
How I fixed it
Exclude the api project from the app project
Build api seperately
Take the resulting .jarfile and put it in a folder inside your app folder called libs
Put this line in your gradle dependencies for your build.gradle (Module: app): implementation fileTree(dir: 'libs', include: ['*.jar'])
This included the finished .jarfile in the appproject and now I can build release. This should be done regardless, because the swagger client shouldnt be edited anyway, as it is generated code. So even just to not always build that part of the project, this should be done.
However, I still dont fully understand why there is this difference between the releaseand the debugbuild. Would be glad for any insight to that.
EDIT: ADDITIONAL INFORMATION
I just found out: if, for some reason, I would have wanted to keep the Module: api in my project I could have done so by removing the two dependencies in my Module: appthat start with implementation fileTree.
The api-project is already included by the dependency api project(path: ':api'). The filetree-lines were the ones causing the problem here, since they were redundant.
However, still no idea why there is a difference between debug and release
I have a project on GitHub that I work on both in the office at home. For about 2 months it was working fine on both machines. Then two weeks ago, it stopped running on my home PC, but still works fine on my work PC.
This is the error I get:
:app:shrinkDebugMultiDexComponents FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:shrinkDebugMultiDexComponents'.
java.io.IOException: Can't read [D:\dev\gitRepo\app\android\app\build\intermediates\multi-dex\debug\allclasses.jar] (Can't process class [__MACOSX/com/stripe/android/._BuildConfig.class] (Invalid magic number [51607] in class))
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
The stripe package that is giving me errors is a 3rd party library that you can find here. I list it as a dependency in my build.gradle file exactly as they say to.
compile 'com.stripe:stripe-android:+'
I have commented out all code pertaining the stripe and the app runs completely fine, so I do know it has something to do with how I am handling that package.
Unfortunately I don't remember exactly what I had done to make this stop working. I do think that the week before this happened I upgraded Android Studio, and spent a considerable amount of time messing with ProGuard configurations.
What I have tried:
Working on the master branch where no ProGuard changes have been made.
Uninstalling and Reinstalling Android Studio
Re-cloning the git repo
Installing API 17 (stripe for eclipse requires this. Not Studio but I gave it a shot).
Contacting stripe customer support but they had no clue.
This stack overflow post. However, there is no Mac computer that has touched the project nor have I personally zipped anything related to stripe.
From here, converted the magic number from Hex to ASCII. The result was Q` which I do not recognize.
I think it may have something to do with something I did for ProGuard, but I don't understand how. I'm on a completely different branch than any Proguard work, with a clean AndroidStudio install, with a clean repository clone, and the project still works fine when I'm in the office.
EDIT
I am running this on the debug BuildType. These are my 3 gradle files. The first is for the entire Project, the second is for the Application Module, and the third is for a local android library Module.
Project build.gradle:
buildscript {
repositories {
jcenter()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
allprojects {
repositories {
jcenter()
maven{ url 'http://download.crashlytics.com/maven' }
}
}
Android Application Module build.gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.app.android"
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
minSdkVersion 16
targetSdkVersion 22
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
buildConfigField 'Boolean', 'enableCrashlytics', 'true'
}
debug {
buildConfigField 'Boolean', 'enableCrashlytics', 'false'
}
adhoc {
debuggable true
signingConfig signingConfigs.debug
buildConfigField 'Boolean', 'enableCrashlytics', 'true'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
}
dependencies {
compile project(':localLibrary')
compile 'com.facebook.android:facebook-android-sdk:3.21.1'
compile 'commons-io:commons-io:2.4'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.android.support:support-v4:22.0.1'
compile 'com.google.android.gms:play-services-identity:8.1.0'
compile 'com.google.android.gms:play-services-plus:8.1.0'
compile 'com.google.android.gms:play-services-maps:8.1.0'
compile 'com.android.support:multidex:1.0.1'
compile 'io.card:android-sdk:5.0.1'
compile 'com.stripe:stripe-android:+'
compile('com.crashlytics.sdk.android:crashlytics:2.5.2#aar') {
transitive = true;
}
}
Local Android Library Module build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 22
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:22.1.0'
compile 'com.google.code.gson:gson:2.2.2'
compile 'com.android.support:multidex:1.0.0'
compile group: 'org.apache.httpcomponents' , name: 'httpmime' , version: '4.3.5'
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5'
}
This problem is probably related to the version of Java that you are running. I had a similar problem and discovered that Java 8 was used for the build. When I changed to Java 7, this build problem was fixed.
In Android Studio go to
File -> Project Structure -> SDK Location
The JDK Location should be Java 1.7.x (Java 7)
Yeah verify both machines have the same Java version, and indeed the same version of Android Studio. The only other thing I can think of is that maybe Stripe is using the build tools bundled with AS to build your apk, and the ones you have installed by default differ slightly and are missing something - see this post I made on a similar problem I had.
I`m working on a project that compiles correctly but crashes on start when I set new maven repository on build.gradle file.
The project is using the lib holoeverywhere, and it crashes with the error: java.lang.NoClassDefFoundError: android.support.v4.app._HoloFragmentInflater$1
Until last month, everything was working fine, but suddenly the older company repository went offline and we created a new one. Now, if I set the older repository on my build.gradle file the app compiles and runs successfully, but if I remove the older repository, it still compiles but when I try to open it crash.
The main problem with that, is that new people trying to compile the code for the first time, using new or older repo, gets the crash on start.
So, I think this can be caused by some cache made by gradle, but looking at the .gradle folder I couldn't find anything.
Can some one help me with that?
Here is the build.gradle file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
mavenCentral()
maven {
url "http://<new_repository_url>/artifactory/simple/libs-release-local/"
}
// if I remove comment from these lines the project runs correctly
//maven {
//url "https://<old_repository_url>/content/groups/AndroidPublicRepository/"
//}
maven {
url "http://holoeverywhere.cf/repo"
}
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1'
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 131
versionName '1.5'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.release
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
packagingOptions {
exclude 'META-INF/license.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/NOTICE.txt'
}
android {
lintOptions {
abortOnError false
}
}
productFlavors {
}
}
configurations {
all*.exclude(group: 'org.springframework', module: 'spring-core')
all*.exclude(group: 'org.springframework', module: 'spring-web')
all*.exclude(group: 'org.hamcrest', module: 'hamcrest-core')
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile 'com.android.support:support-v13:19.1.0'
compile 'org.holoeverywhere:library:2.1.0'
compile 'com.viewpagerindicator:viewpagerindicator:2.4.1'
compile 'com.googlecode.libphonenumber:libphonenumber:5.9'
compile 'de.keyboardsurfer.android.widget:crouton:1.8.4'
compile 'com.google.code.gson:gson:2.3'
compile 'com.octo.android.robospice:robospice:1.4.14'
compile 'com.octo.android.robospice:robospice-cache:1.4.14'
compile 'com.octo.android.robospice:robospice-spring-android:1.4.14'
compile 'org.springframework.social:spring-social-core:1.0.2.PATCHED'
compile('org.springframework.android:spring-android-auth:1.0.1.RELEASE') {
exclude group: 'org.springframework.social', module: 'spring-social-core'
}
compile project(':addon-preferences-2.1.0')
}
I recommend you to remove HoloEverywhere from your app. It was a great library, but it isn't now. It's not very difficult: just change imports, some little adjustments and minSdkVersion = 15. Other option: Material Design.
Anyway, if you can't remove it or you can't do it right now:
HoloEverywhere had a dependency with a patched support-v4. I think the problem is that you don't have this patched version at your maven repository. You can find this code in the branch support-library.
Here is the content of my build.gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven {
credentials {
username artifactoryUserName
password artifactoryPassword
}
url 'http://test:8081/artifactory/libs-release-local'
}
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
allprojects {
repositories {
maven {
credentials {
username artifactoryUserName
password artifactoryPassword
}
url 'http://test:8081/artifactory/libs-release-local'
}
mavenCentral()
maven { url 'http://repo1.maven.org/maven2' }
jcenter()
} }
Here is the content of app\build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
lintOptions {
abortOnError false
}
defaultConfig {
applicationId "test.com"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
signingConfigs {
aseeConfig {
storeFile file("test.keystore")
storePassword "test123"
keyAlias "AndroidKey"
keyPassword "test123"
}
}
buildTypes {
release {
signingConfig signingConfigs.aseeConfig
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
prod.initWith(buildTypes.release)
prod {
signingConfig signingConfigs.aseeConfig
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
} }
dependencies {
//compile 'com.google.android:support-v4:r13'
compile 'com.google.android:google-play-services:4.1.32'
compile 'com.devsmart.android:devsmart-lib:1.0.0'
compile 'com.jeremyfeinstein.slidingmenu.lib:sliding-menu:1.0.0'
compile 'com.viewpagerindicator:viewpager-indicator:2.4.1'
///compile 'com.google.android.gms:google-play-services_lib:4.1.32'
compile 'com.emilsjolander:sticky-list-headers:1.0.0'
//compile 'com.actionbarsherlock:actionbar-sherlock:4.2.0'
compile 'com.mobeta.android.dslv:drag-sort-list-view:0.6.1'
compile 'com.threegvision.products:inigma_sdk_pro:3.24'
compile 'org.afree:a-free-chart:1.0.0'
compile 'org.afree:a-free-graphics:1.0.0'
compile 'net.simonvt:datepicker:1.0'
//compile 'eu.inmite:android-styled-dialogs:1.1'
compile 'com.nineoldandroids:nine-old-androids:2.4.1'
compile 'com.shinobicontrols.charts:shinobicharts:1.5.0-5'
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.daimajia.slider:library:1.1.5#aar'
compile 'com.github.bumptech.glide:glide:3.6.0'
compile 'com.journeyapps:zxing-android-embedded:3.0.1#aar'
compile 'com.google.zxing:core:3.2.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/actionbarsherlock-4.2.0.jar')
compile files('libs/android-styled-dialogs-1.1.1-sources.jar')
compile files('libs/android-support-4.0.jar')
}
I can't build my project . I am getting this error:
I faced this kind of issue once but I don't remember exactly how to fix it.
As I rememeber, I follow this link
It's seem because there are many module dependent on difference support-v4 lib. So add multiDexEnabled true may works.
Also try to set all modules' dependency to a same version of support-v4. You can look at these link to known how to exclude compile v4 link1 link2 link3
If it still doesn't work, try to clean project, restart Studio, even restart your computer(I don't know why but this worked for me once)
Hope this helps.
in your build.gradle file set your compileSdkVersion 20.0.0 and buildToolsVersion "21.0.0"
Generally, it is because of resource conflicts within your modules.For sample, there are two ic_launcher.png in your app.(one from module and one from your app)
I searched to check resource conflicts but I didn't find official solution.
I only solved by this ways, remove each module and test it is being conflict or not. That's the simplest way to solve. I hope this will help you.
Here below are another suggestion....
I found also this way, one person(I didn't remember name) use safe delete to check conflict.
And some Q&A said, to add multiDexEnabled:true. That config is to increase dex file size. You can also use multidex support library .
The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multidex configuration.
Here is the link for multiDex:
https://developer.android.com/tools/building/multidex.html
But documentation said you should be careful to use that.
My android application uses the following config:
Gradle - 0.12.+
Contents of build.gradle file
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
}
repositories {
mavenLocal()
mavenCentral()
}
apply plugin: 'com.android.library'
apply plugin: "jacoco"
dependencies {
compile 'commons-collections:commons-collections:3.2.1'
compile 'org.slf4j:slf4j-android:1.6.1-RC1'
// dependency injection
compile('org.roboguice:roboguice:2.0') {
exclude module: 'cglib'
exclude module: 'aopalliance'
exclude module: 'guice'
}
compile files('libs/guice-3.0-no_aop.jar')
compile 'javax.inject:javax.inject:1'
/*
* Test dependencies.
*/
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
}
android {
buildToolsVersion "20.0"
compileSdkVersion 19
buildTypes {
debug {
runProguard false
testCoverageEnabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 100
versionName "1.0.0"
}
/*
* Workaround for packaging bug in Android Gradle plugin regarding duplicate files.
*/
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'LICENSE.txt'
}
}
All my tests run successfully when property testCoverageEnabled is set to false. On setting it to true, the following exception is thrown when running the tests
Caused by: java.lang.VerifyError: *** Some class ***
at dalvik.system.DexFile.defineClass(Native Method)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:211)
at dalvik.system.DexPathList.findClass(DexPathList.java:313)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:51)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
The error happens on the line when mocks are initialised within the tests.
Has anyone managed to generate code coverage metrics for android application which uses mockito library for testing?
The following link was very useful in explaining the problem I encountered: http://www.androidpuzzles.com/168_17620080/
I subsequently switched the source and target compatibility settings to Java 1.5 and I was able to run the unit and UI tests (which used both mockito and espresso) and generate code coverage report using Jacoco.
If I had to retain Java 1.7 settings, the workaround would have been to change the scope of private methods in the class being tested to either protected or public scope. This would have then allowed me to generate the code coverage report (overcoming the issue as identified in the link included).
Jacoco coverage support has been added to the gradle plugin since 0.10.0. See http://tools.android.com/tech-docs/new-build-system.
Not quite sure I understand why you have such a complex gradle file.
You need to compile against Java 1.5 version.
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_5
targetCompatibility JavaVersion.VERSION_1_5
}
https://code.google.com/p/android/issues/detail?id=69174
This issue has been fixed in build tools version 21+
android {
buildToolsVersion "21.1.2"
compileSdkVersion 19
...
}
Upgrade build tools to 21+ to retain Java 1.7 compatibility.