I am creating a signed APK for the next update of my app. But when i transfer this APK file to my devices and install it, it crashes on opening the app.
Here is my project level gradle file
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:2.0.0-alpha6'
}
}
allprojects {
repositories {
jcenter()
}
}
And here is my module gradle file code:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.0'
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.washkart.activities"
minSdkVersion 15
targetSdkVersion 19
// Enabling multidex support.
multiDexEnabled true
}
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
dataBinding {
enabled = true
}
}
dependencies {
compile files('libs/joda-time-2.4.jar')
compile(name:'acra-4.7.0', ext:'aar')
compile project(':ViewPagerIndicator')
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.google.android.gms:play-services-identity:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:multidex:1.0.0'
}
apply plugin: 'com.google.gms.google-services'
And i have added below lines in my proguard file to avoid the warning/error which i got durng signing the APK:
-keepnames class org.apache.** {*;}
-keep class org.apache.** {*;}
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.app.** { *; }
-dontnote android.support.v4.**
-keep class org.joda.time.** { *; }
-keep interface org.joda.time.** { *;}
-keep class android.support.v7.app.** { *; }
-keep interface android.support.v7.app.** { *; }
-dontskipnonpubliclibraryclassmembers
-dontwarn org.apache.commons.logging.LogFactory
-dontwarn org.apache.http.annotation.ThreadSafe
-dontwarn org.apache.http.annotation.Immutable
-dontwarn org.apache.http.annotation.NotThreadSafe
-dontwarn org.jodatime.time.**
-dontwarn org.joda.convert.**
-dontwarn org.apache.http.**
-dontwarn android.net.**
I have android studio 1.5.1 and testing on Android 4.4.2.
And the procedure which i used to generate in Build>Generate Signed APK>Selecting the module from dropdown > Add keystore file, alias and password> Build type = release > finish
I was facing the same issue, the problem is in your proguard file.
you have enabled the proguard when used minifyEnabled true.
Either disable it to disable to proguard or read about how to use proguard from here as it discards the class files and other resource that are not added in proguard-rules.pro.
Related
I am trying to port my app from GMS to (G+H) using HMS Toolkit.
After using the Toolkit Convertor, the following line throws an unresolved reference error on import org.xms.f.auth.ExtensionAuth asking to define xms. This obviously means the xmsadapter files (which are generated by the HMS Toolkit Convertor) have not been imported.
How can I fix this error to import the .xms files on import org.xms.f.auth.ExtensionAuth I feel like there's a dependancy that I'm missing?
You can also check your configured obfuscation scripts first.
XMS code generated using the Add HMS API policy will increase the size of your app. You can enable the code reduction function by adding or modifying the following configurations in the app/build.gradle file:
android {
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
If an error message such as "Can't find...", "NoClassDefFoundError", "ClassNotFoundException", "NoSuchFieldException", or "NoSuchMethodException" is displayed after minifyEnabled is set to true, configure the following XMS obfuscation rules in app/proguard-rules.pro:
-ignorewarnings
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-keep class com.hianalytics.android.**{*;}
-keep class com.huawei.updatesdk.**{*;}
-keep class com.huawei.hms.**{*;}
-keep class com.huawei.agconnect.**{*;}
-keep interface com.huawei.agconnect.**{*;}
-keep class com.huawei.hmf.**{*;}
-keep class com.google.android.gms.**{*;}
-keep interface com.google.android.gms.**{*;}
-keep class com.google.firebase.**{*;}
-keep interface com.google.firebase.**{*;}
-keep class org.xms.**{*;}
-keep interface org.xms.**{*;}
For details,you can refer to this Docs.
I just updated project gradle from 2.3 to 4.0.1. Android studio version 4.0.1 and 3.6.3
tried to access method org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier.(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V from class org.gradle.api.plugins.AndroidMavenPlugin$8
build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.50'
repositories {
google()
jcenter()
mavenCentral()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath "com.github.dcendents:android-maven-gradle-plugin:1.5"
classpath 'com.google.gms:google-services:4.3.3'
classpath 'io.fabric.tools:gradle:1.25.4'
}
}
allprojects {
repositories {
google()
jcenter()
maven{
url 'https://dl.bintray.com/cometchat/CometChat'
}
maven { url 'https://maven.google.com' }
maven { url "https://jitpack.io" }
maven { url "https://github.com/syrjs/maven/raw/master"}
// maven { url "https://github.com/paypal/paypalcheckout-android/raw/nativeSDK"}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle app level
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'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.dousic.music"
minSdkVersion 19
targetSdkVersion 28
versionCode 9
versionName "1.0.8"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
//Signing configurations for build variants "release"
// signingConfigs {
// release {
// storeFile file("F:\\Samsung_jks\\galaxy_dousic.jks")
// storePassword "cybernext123"
// keyAlias "dousic"
// keyPassword "cybernext123"
// }
// }
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// signingConfig signingConfigs.release
}
}
dexOptions {
javaMaxHeapSize "5120M"
}
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 {
implementation fileTree(include: ['*.jar'], dir: 'libs')
// implementation 'com.android.support:appcompat-v7:27.1.1'
testImplementation 'junit:junit:4.12'
//noinspection GradleCompatible
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor "com.jakewharton:butterknife-compiler:8.8.1"
// implementation 'com.google.android.material:material:1.2.0'
implementation 'androidx.navigation:navigation-ui:2.3.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
// implementation 'androidx.navigation:navigation-fragment:2.3.0'
//implementation "com.koushikdutta.ion:ion:2.1.8"
implementation 'org.jsoup:jsoup:1.10.2'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'org.apache.httpcomponents:httpcore:4.3.2'
implementation 'org.apache.httpcomponents:httpmime:4.3.3'
implementation 'com.github.bumptech.glide:glide:3.5.2'
implementation 'com.pnikosis:materialish-progress:1.5'
implementation 'com.splitwise:tokenautocomplete:1.3.3'
implementation 'com.google.firebase:firebase-database:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.android.support:cardview-v7:28.0.0'
// implementation 'com.mcxiaoke.volley:library:1.0.17'
//implementation 'org.jsoup:jsoup:1.8.1'
implementation 'de.hdodenhof:circleimageview:2.1.0'
implementation 'com.wang.avi:library:2.1.3'
/* implementation 'com.inscripts:CometChat:7.9.1'
implementation 'com.inscripts:CometChatUI:7.9.1'*/
implementation 'com.inscripts:CometChat:7.33.0'
implementation 'com.inscripts:CometChatUI:7.33.0'
implementation files('libs/YouTubeAndroidPlayerApi.jar')
implementation 'com.squareup.okhttp3:okhttp:3.3.1'
implementation 'com.loopj.android:android-async-http:1.4.4'
implementation 'org.apache.httpcomponents:httpcore:4.3.2'
implementation 'org.apache.httpcomponents:httpmime:4.3.3'
implementation project(path: ':library')
implementation project(path: ':videocompressor')
//facebook
implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
//Google login
implementation 'com.google.firebase:firebase-database:16.0.5'
implementation 'com.google.firebase:firebase-storage:16.0.5'
implementation 'com.google.firebase:firebase-auth:16.1.0'
implementation 'com.firebaseui:firebase-ui-database:2.0.1'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
//Twiiter
implementation 'com.twitter.sdk.android:twitter:3.1.1'
// (Optional) Monetize using mopub
implementation 'com.twitter.sdk.android:twitter-core:3.1.1'
implementation 'com.twitter.sdk.android:tweet-ui:3.1.1'
implementation 'com.twitter.sdk.android:tweet-composer:3.1.1'
implementation 'com.twitter.sdk.android:twitter-mopub:3.1.1'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.github.deano2390:MaterialShowcaseView:1.2.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.3'
implementation 'com.github.pedroSG94:AutoPermissions:1.0.3'
//Showcase lib
implementation 'com.github.mreram:ShowCaseView:1.0.5'
// full exoplayer library
// implementation 'com.google.android.exoplayer:exoplayer:2.8.2'
implementation 'org.greenrobot:eventbus:3.0.0'
//Audio player design
implementation 'net.the4thdimension:audio-wife:1.0.3'
//Comment loading libery
implementation 'com.ethanhua:skeleton:1.1.1'
implementation 'io.supercharge:shimmerlayout:2.1.0'
implementation 'com.braintreepayments.api:drop-in:3.7.1'
implementation 'com.android.volley:volley:1.1.0'
//Strip
implementation 'com.stripe:stripe-android:9.0.0'
implementation 'com.paypal.sdk:paypal-android-sdk:2.14.2'
//Exo player
implementation 'com.google.android.exoplayer:exoplayer:r2.2.0'
// implementation 'com.google.code.ksoap2-android:ksoap2-android-assembly:3.6.1'
// implementation 'com.braintreepayments.api:braintree:2.22.0'
/* implementation('com.crashlytics.sdk.android:crashlytics:2.9.4#aar') {
transitive = true;
}*/
// implementation 'com.applozic.communication.uiwidget:mobicomkitui:5.8.4'
// implementation 'com.github.takusemba:spotlight:1.6.0'
// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation project(':library')
implementation project(':IAP5Helper')
// implementation 'com.paypal.pyplcheckout:nativexo:3.4.5'
}
apply plugin: 'com.google.gms.google-services'
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
package com.example.android.favoritetoys;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
// TODO (1) Declare a TextView variable called mToysListTextView
TextView mToysListTextView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mToysListTextView = (TextView).findViewById(R.id.tv_toy_names);
// TODO (3) Use findViewById to get a reference to the TextView from the layout
// TODO (4) Use the static ToyBox.getToyNames method and store the names in a String array
String[] toyNames = ToyBox.getToyNames();
// TODO (5) Loop through each toy and append the name to the TextView (add \n for spacing)
for (String toyName : toyNames) {
mToysListTextView.append(toyName + "\n\n\n");
}
Go to your build.gradle file. there you will find the code given below
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
applicationId "com.android.example.favoritetoys"
minSdkVersion 10
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.1.0'
}
You have to do just change it buildToolsVersion '25.0.2' to according your "build Tool Version".
mine is working with strong textbuildToolsVersion '25.0.1'
you need to import one last class, just add
import android.widget.TextView;
If I set minifyEnabled = true in Gradle setting for my Android app, calling the JNI function RegisterNatives() from the JNI shared library doesn't find its target class anymore. I tried a number of ProGuard rules but still can't get it to work.
Java code:
package net.pol_online.hyper;
...
public class Hyper extends Application {
...
public native static void initializeLibrary(Context context, int maxImageMemoryCacheSize);
...
}
JNI code:
static JNINativeMethod _methods[] = {
{"initializeLibrary", "(Landroid/content/Context;I)V", reinterpret_cast<void*>(&_InitializeLibrary)},
...
}
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
...
_hyperClass = env->FindClass("net/pol_online/hyper/Hyper");
jint error = env->RegisterNatives(_hyperClass, _methods, sizeof(_methods) / sizeof(JNINativeMethod));
assert(error == JNI_OK);
...
}
Gradle build settings (using the experimental Gradle NDK plug-in for Android Studio):
android.buildTypes {
release {
minifyEnabled = true
proguardFiles.add(file("proguard-rules.txt"))
ndk.with {
CFlags.add("-Werror")
cppFlags.add("-Werror")
}
}
}
ProGuard rules:
-keep class butterknife.** {
*;
}
-keep class **$$ViewBinder {
*;
}
-keepclasseswithmembernames class * {
#butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
#butterknife.* <methods>;
}
-dontwarn butterknife.internal.**
-keep public class net.pol_online.hyper.**
-dontnote android.support.v4.**
-dontwarn android.support.v4.**
The crash at launch:
Failed to register native method net.pol_online.hyper.Hyper.initializeLibrary(Landroid/content/Context;I)V in /data/app/net.pol_online.hyper-1/base.apk
java.lang.NoSuchMethodError: no static or non-static method "Lnet/pol_online/hyper/Hyper;.initializeLibrary(Landroid/content/Context;I)V"'
You do not include the default Proguard configuration for android:
proguardFiles getDefaultProguardFile('proguard-android.txt')
which includes a configuration to keep all native methods:
-keepclasseswithmembernames class * {
native <methods>;
}
This should fix the issue as well and is highly suggested.
I am developing android application in Android Studio. There is no problem when I build the project an export signed APK without Proguard, but when I try to build the project with ProGuard(minifyEnabled true), there is an Proguard build failed with error like this:
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Can't write [user\myapplication\app\build\intermediates\transforms\proguard\release\jars\3\1f\main.jar] (Can't read [user]sdkpath\SDK\build-tools\23.0.0\renderscript\lib\renderscript-v8.jar(;;;;;;**/*.class)] (Duplicate zip entry [renderscript-v8.jar:android/support/annotation/Keep.class]))
Here is my build.gradle codes
...
defaultConfig {
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
checkReleaseBuilds false
}
}
dependencies {
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile project(':libraries:gpuimage')
compile 'it.sephiroth.android.library.horizontallistview:hlistview:1.2.2'
}
Here is my proguard-rule.pro
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.view.View {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
public <init>(android.content.Context, android.util.AttributeSet, int);
public void set*(...);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.content.Context {
public void *(android.view.View);
public void *(android.view.MenuItem);
}
-keep class *.R
-keep class *.R$* {*;}
-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }
-keep public class * extends android.support.v4.view.ActionProvider {
public <init>(android.content.Context);
}
## Google AdMob specific rules ##
## https://developers.google.com/admob/android/quick-start ##
-keep public class com.google.ads.** {
public *;
}
## Google Analytics 3.0 specific rules ##
-keep class com.google.analytics.** { *; }
#-keep class it.sephiroth.** {*;}
-dontwarn it.sephiroth.**
Proguard Troubleshooting Say this
Warning: can't write resource ... Duplicate zip entry
Your input jars contain multiple resource files with the same name. ProGuard continues copying the resource files as usual, skipping any files with previously used names. Once more, the warning may be an indication of some problem though, so it's advisable to remove the duplicates. A convenient way to do so is by specifying filters on the input jars. There is no option to switch off these warnings.
android The standard Android build process automatically specifies the input jars for you. There may not be an easy way to filter them to remove these warnings. You could remove the duplicate resource files manually from the input and the libraries.
But i didn't figured out the which jar i added twice in my build..!
This might be related to a bug in renderscript-v8.jar in BuildTools 23.0.0, which included it's own copy of the annotation library and might cause error when used with some other support library.
I would suggest you try use BuildTools 23.0.3 and see if the problem goes away. 23.0.3 also included several other fixes for RenderScript.