So I am learning how to code on Android these days and at the moment I am facing a ridiculous problem! My debuggable built works just fine when I install it on my mobile for testing but when I create a signed built and try to run it on my mobile it instantly crashes :( I need help desperately! Since I am really really new to Android it would be greatly appreciated if whoever answers this question keeps my skill level in mind. Oh btw I am using Android Studio 1.5.1
Most likely the issue is occurring because Proguard (the tool that minifies and obfuscates your code) is removing a required class, most likely from a library that you are using. If you update your question with any libraries you are using I can give a more specific answer.
In your /app/build.gradle
file (keep in mind that Android has two separate build.gradle
files, you want the one inside of the app/
folder) you will be able to see two separate build types, "debug" and "release." Signing and minifcation happen in the "release" build type.
Your "release" build type will look something like this:
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
debuggable false
signingConfig signingConfigs.release
}
In order to tell Proguard to keep specific classes you will need to edit/create your proguard-rules.pro
file in the same directory as your build.gradle
file.
Inside of the proguard-rules.pro
file you will want to add the appropriate -keep class package.name.** {*;}
line. I can't tell you exactly what this is because I don't know exactly which library/class is causing your app to crash. You can search Google/StackOverflow for Proguard issues which each of your specific libraries and add the appropriate Proguard configurations.
Once you have created your Proguard file, ensure that you have this line in your release
build type:
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'