How to free library module from pro-guard in android gradle

The version of my Android application is disabled with the following exception

java.lang.NoSuchMethodError: no static or non-static method "Lcom/mm/android/dhproxy/client/DHProxyClient;.InitWithName(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)I"

This error was not found in the debug version and, therefore, due to protection, I think.

The above class is in one of the modules that also use JNI libraries. My proguard rules for the application module file below

 -keepattributes InnerClasses -dontoptimize -keep class com.mm.android.dhproxy.client.DHProxyClient -keepclasseswithmembernames class * { native <methods>; } -keep class mypackage.MyCallbackClass { void myCallbackMethod(java.lang.String); } -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } -printmapping build/outputs/mapping/release/mapping.txt 

The build.gradle file for the corresponding module is below

apply plugin: 'com.android.library'

 android { compileSdkVersion 23 buildToolsVersion "23.0.3" compileOptions.encoding = 'ISO-8859-1' defaultConfig { minSdkVersion 14 targetSdkVersion 23 } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } } dependencies { compile files('libs/IPlaySDK.jar') compile files('libs/ToUProxy.jar') } 

even after adding the line -keep class com.mm.android.dhproxy.client.DHProxyClient I see that the use.txt file contains the following entries

 com.mm.android.dhproxy.client.DHProxyClient: 29:35:public boolean initWithName(java.lang.String,int,java.lang.String,java.lang.String) 64:69:public int delPort(int) 136:141:public int queryRate(int,com.mm.android.dhproxy.client.DHProxyRateParam) 158:163:public int p2pSetOption(int,int) 180:185:public int p2pGetOption(int) 192:197:public int exit() private native int InitWithName(java.lang.String,int,java.lang.String,java.lang.String) private native int DelPort(int,int) private native int P2PSetOption(int,int,int) private native int P2PGetOption(int,int) private native int QueryRate(int,com.mm.android.dhproxy.client.DHProxyRateParam,int) private native int Exit(int) com.mm.android.dhproxy.client.DHProxyRateParam 

Thanks in advance.

+5
source share
3 answers

The solution is to look for the methods and classification that should be freed and add them to the proguard rules as follows (here I had to save the files in the com.mm. ** and com.company classes. * * Where ** is valid like wild char

 -keep class com.mm.** {*;} -keep class com.company.** {*;} -keepclassmembers class com.mm.** {*;} -keepclassmembers class com.company.** {*;} 
+3
source

If you use external / separate source libraries in your main project / application, you should not use proguard in library modules. Instead, you replace the following:

 buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt' } debug { minifyEnabled false } } 

with the following (in build.gradle libraries / libraries):

 buildTypes { release { consumerProguardFiles 'proguard-project.txt' } } 

where proguard-project.txt is the file containing the proguard rules for your library project. When creating an application (in debug or release mode), the compiler will abide by all the rules (in the library and in the application).

Source: this fooobar.com/questions/112773 / ...

+2
source

Can you try setting minifyEnabled to true and generate the release build using the following command.

./gradlew assembleRelease if you use mac gradlew assembleRelease if you use widows

Check the assembly after running the command and see if it works

0
source

All Articles