ERROR: couldn & amp; #39; t find native method cannot be found in jni native methods of apk when apk is compiled by mm in Android4.4.

Source: Internet
Author: User

Some native classes cannot be found when the apk is compiled by mm in Android4.4, because it is optimized by produard. I have not encountered this problem in Android4.2.

1. What does proguard do? ProGuard is a free java File compression, optimization, and obfuscator. It detects and deletes unused classes, fields, methods, and attributes. It deletes useless instructions and uses bytecode for maximum optimization. It uses meaningless names to rename classes, fields, and methods ..

ProGuard is used:

(1) Create compact code documents for faster network transmission, fast loading, and smaller memory usage;
(2) It is difficult to use reverse engineering to create programs and libraries;
(3) It can delete code not called from the source file;
(4) Make full use of the advantages of rapid loading of Java 6 to detect and return class files existing in Java 6 in advance.

2. Because proguard is a obfuscation tool, the mk file of android supports two methods:
1) Specify the native method that does not need to be confused with the proguard. flags file of the variable, and add it under the mk file:

For example: LOCAL_PROGUARD_FLAG_FILES: = $ (LOCAL_PATH)/proguard. flags

The content of proguard. flags is as follows:

# ------------- Begin: proguard configuration common for all Android apps ----------
-Optimizationpasses 5


# Classes with different names are not generated during obfuscation.
-Dontusemixedcaseclassnames

# Specify not to ignore non-public library classes
-Dontskipnonpubliclibraryclasses
-Dontpreverify
-Verbose

-Dump class_files.txt
-Printseeds seeds.txt
-Printusage unused.txt
-Printmapping mapping.txt
-Optimizations! Code/simplification/arithmetic ,! Field /*,! Class/merging /*,! Method/removal /*

# Allow access to and modify members of classes and classes with modifiers during Optimization
#-Allowaccessmodification

# Retain the specified attribute
-Keepattributes * Annotation *
-Renamesourcefileattribute SourceFile
-Keepattributes SourceFile, LineNumberTable
-Repackageclasses''

-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. app. backup. BackupAgentHelper
-Keep public class * extends android. preference. Preference
-Keep public class com. android. vending. licensing. ILicensingService

# Protect members of a specified class. If this class is protected, it will be better protected.
-Keepclassmembers class * implements java. io. Serializable {
Static final long serialVersionUID;
Private static final java. io. ObjectStreamField [] serialPersistentFields;
Private void writeObject (java. io. ObjectOutputStream );
Private void readObject (java. io. ObjectInputStream );
Java. lang. Object writeReplace ();
Java. lang. Object readResolve ();
}

-Keepclasseswithmembernames class *{
Native ;
}
-Keepclasseswithmembers class *{
Public (Android. content. Context, android. util. AttributeSet );
}
-Keepclasseswithmembers class *{
Public (Android. content. Context, android. util. AttributeSet, int );
}
-Keepclassmembers class * extends android. app. Activity {
Public void * (android. view. View );
}
-Keepclassmembers class **. R$ *{
Public static ;
}
-Keepclassmembers enum *{
Public static ** [] values ();
Public static ** valueOf (java. lang. String );
}

-Keep public class *{
Public protected *;
}

-Keep class * implements android. OS. Parcelable {
Public static final android. OS. Parcelable $ Creator *;
}
# ------------- End: proguard configuration common for all Android apps ----------

# ------------- Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# Removes such information by default, so configure it to keep all of it.
# Protect the specified optional attributes
-Keepattributes Signature
# Gson specific classes
-Keep class sun. misc. Unsafe {*;}

# Application classes that will be serialized/deserialized over Gson
#-Keep public class net. unitepower. mcd. vo .**{*;}
# ------------- End: proguard configuration for Gson ----------


2) compile the project and do not use code obfuscation tools for code obfuscation.
For example, LOCAL_PROGUARD_ENABLED: = disabled
3) If this parameter is not set, LOCAL_PROGUARD_ENABLED: = full is used by default to confuse all the project code.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.