ÇóÖª ÎÄÕ ÎÄ¿â Lib ÊÓƵ iPerson ¿Î³Ì ÈÏÖ¤ ×Éѯ ¹¤¾ß ½²×ù Modeler   Code  
»áÔ±   
 
  
 
 
     
   
·ÖÏíµ½
Android 4.0 ÖÐÓÉProGuardÒý·¢µÄÒ»³¡Ñª°¸
 

×÷Õߣºyihongyuelan£¬·¢²¼ÓÚ2012-11-9,À´Ô´£ºCSDN

 

°¸¼þ»¹Ô­£º

ÐÞ¸ÄAndroid 4.0Ô´ÂëÖеÄSetting£¬Ìí¼ÓÒ»ÏÄÜÖ®ºó£¬ÔÚengģʽϱàÒ룬һÇÐÕý³££¬ËìÌá½»´úÂëµ½·þÎñÆ÷¡£µÚ¶þÌ죬´«À´Ø¬ºÄ£¬SettingÉÏÐÂÌí¼ÓµÄ¹¦ÄÜÎÞ·¨Ê¹Óã¬Ò»µã»÷Ôò±¨´í¡£

°¸¼þ·ÖÎö£º

ÉÏ´«´úÂë֮ǰ£¬ÒѾ­ÔÚ±¾µØ±àÒë²âÊÔ¹ý£¬Õ¦»áÓдíÄØ£¿£¿£¡£¡¹ÜËüÈýÆ߶þʮһ£¬²ÙÆðadb logcatץȡlog½øÐзÖÎö¡£²»¿´²»ÖªµÀ£¬Ò»¿´ÏÅÒ»Ìø£¬logÖÐÏÔʾµÄ´íÎóÐÅÏ¢¾¹È»ÊÇClassNotFound£¬Ò²¾ÍÊÇÕÒ²»µ½ÏàÓ¦µÄÀ࣬ÄѵÀÎÒÉÏ´«µÄʱºòÒÅ©ÁËÂð(ÓÐÕâÖÖ¿ÉÄÜ)£¿ÂíÉϲ鿴Ìá½»¼Ç¼£¬Öð¸ö¼ì²éÌá½»µÄÎļþ£¬È«²¿Ìá½»ÁË°¡£¡Õ¦»á³öÏÖClassNotFoundÄØ£¿ÕâʱºòÕ¦°ìÄØ£¿Àä¾²ÏÂÀ´·ÖÎöºó¿ÉÒÔÖªµÀ£¬±¾µØ²âÊÔÒ»°ãÊÇÔÚengģʽϱàÒëµÄ£¬¶øÕâ´Î±¨´íµÄÊÇ·þÎñÆ÷ÔÚusrģʽϱàÒë´¦³öÀ´µÄ¡£ÄѵÀeng±àÒëºÍusr±àÒë³öÀ´µÄ½á¹û²»Ò»Ö£¿£¿£¡£¡

°¸¼þ½øÒ»²½·ÖÎö£º

ÔÚ±¾µØÑ¡Ôñusr±àÒëģʽ£¬±àÒë´úÂë½øÐвâÊÔ£¬¹ûÈ»³öÏÖÁËÓë·þÎñÆ÷Ò»ÑùµÄ´íÎ󣬼´ClassNotFound¡£

1.¼ÈÈ»engģʽ±àÒëµÄ´úÂëÄܹ»Õý³£ÔËÐУ¬Ö¤Ã÷´úÂëÂß¼­ÒÔ¼°¹¦Äܶ¼ÊÇOKµÄ¡£

2.usr±àÒë³öÀ´³öÏÖClassNotFoundµÄÎÊÌ⣬֤Ã÷usrºÍeng±àÒëģʽ²»Í¬µ¼Ö±àÒë½á¹û²îÒì¡£

3.±È½ÏengģʽºÍusrģʽ±àÒë³öÀ´µÄSettings.apk£¬·¢ÏÖ´óС¾¹È»²»Ò»Ö£¬ÓÃapktool·´½âºó¶Ô±È·¢ÏÖ£¬usrģʽϱàÒëµÄSettings.apkÖеÄÈ·ÉÙÁËÒ»¸öÀà(ºóÎÄÓÃlostClass.java´úÌæ)¡£

°¸¼þµ÷²é£º

¼ÙÉèÒ»£º

ÄѵÀÊDZàÒë¹ý³ÌÖÐûÓн«lostClass.java±àÒë½øÈ¥£¿

ÑéÖ¤Ò»£º

²é¿´±àÒë¹ý³ÌÖÐÊÇ·ñÓжÔlostClass.java½øÐбàÒë¡£

1.µÚÒ»Öֲ鿴·½·¨¡£

´ò¿ªÔ´ÂëÖÐSettingsÎļþ¼ÐϵÄAndroid.mkÎļþÎÒÃÇ¿ÉÒÔ·¢ÏÖÒÔÏ´úÂ룺

LOCAL_SRC_FILES := $(call all-java-files-under, src)

ÎÒÃÇÔÚÕâ¾ä´úÂëºóÌí¼ÓÒÔÏÂÄÚÈÝ£º

$(warning SevenTest LOCAL_SRC_FILES : $(LOCAL_SRC_FILES))

±£´æºóÖÕ¶ËÖÐÖ´ÐбàÒ룬ÎÒÃÇ¿ÉÒÔ¿´µ½srcÎļþÐÅÏ¢Êä³öÔÚÖÕ¶ËÉÏ¡£¸´ÖƵ½ÎļþÖвéÕÒlostClass.java£¬¿ÉÒÔÕÒµ½£¬Òò´Ë¿ÉÒÔÍÆ·­4µÄ¼ÙÉè¡£

2.µÚ¶þÖֲ鿴·½·¨¡£

²é¿´APKµÄ±àÒë´ò°üÁ÷³Ì£¬Èçͼ1£º

¸ù¾ÝÒÔÉÏÁ÷³Ì£¬ÎÒÃÇ¿ÉÒÔÕÒµ½Ã¿Ò»²½¶ÔÓ¦µÄmkÎļþ£¬ÕâÀïÎÒÃÇÕÒµ½AndroidSouceCode/build/core/definitons.mkÖÐ×¢ÊÍÒÔÏ´úÂ룺

define compile-java
$(hide) rm -f $@
$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
$(hide) mkdir -p $(dir $@)
$(hide) mkdir -p $(PRIVATE_CLASS_INTERMEDIATES_DIR)
$(call unzip-jar-files,$(PRIVATE_STATIC_JAVA_LIBRARIES),$(PRIVATE_CLASS_INTERMEDIATES_DIR))
$(call dump-words-to-file,$(PRIVATE_JAVA_SOURCES),$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list)
$(hide) if [ -d "$(PRIVATE_SOURCE_INTERMEDIATES_DIR)" ]; then \
	   find $(PRIVATE_SOURCE_INTERMEDIATES_DIR) -name '*.java' >> $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-lis; \
fi
$(hide) tr ' ' '\n' < $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list \
    | sort -u > $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
$(hide) $(1) -encoding UTF-8 \
    $(strip $(PRIVATE_JAVAC_DEBUG_FLAGS)) \
    $(if $(findstring true,$(LOCAL_WARNINGS_ENABLE)),$(xlint_unchecked),) \
    $(2) \
    $(addprefix -classpath ,$(strip \
        $(call normalize-path-list,$(PRIVATE_ALL_JAVA_LIBRARIES)))) \
    $(if $(findstring true,$(LOCAL_WARNINGS_ENABLE)),$(xlint_unchecked),) \
    -extdirs "" -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
    $(PRIVATE_JAVACFLAGS) \
    \@$(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq \
    || ( rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) ; exit 41 )
#Seven×¢ÊÍ
#$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list
#$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
    $@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
endef

define transform-java-to-classes.jar
@echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))"
$(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH))
#Seven×¢ÊÍ
#$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR)
endef 

ÕâÑùÎÒÃÇÔÚÖÕ¶ËÖÐÖ´ÐбàÒëÃüÁîºó£¬¿ÉÒÔÔÚ·¾¶£º

AndroidSourceCode/out/target/common/obj/APPS/Settings_intermediates/classesÕÒµ½ÒÔÏÂÁ½¸öÎļþ£º

java-source-listºÍjava-source-list-uniq£¬ÔÚÆäÖÐËÑË÷lostClass.java¼´¿ÉÒÔÕÒµ½¡£

ͨ¹ýÒÔÉϲ鿴¿ÉÒÔÖªµÀ£¬lostClass.javaÔÚÊDZ»±àÒëÁ˵ģ¬×îºóΪÁËÑéÖ¤£¬ÎÒÃÇ¿ÉÒÔͨ¹ýjd-guiÕâ¸ö¹¤¾ßÀ´²é¿´AndroidSourceCode/out/target/common/obj/APPS/Settings_intermediates/classes.jar£¬Í¨¹ý²é¿´¸ÃjarÎļþÖаüº¬ÁËlostClass.java£¬´Ó¶ø¼ÙÉèÒ»Åųý¡£

¼ÙÉè¶þ£º

Settings.apkÔÚ´ò°üµÄʱºò³öÏÖÒì³£¡£

ÑéÖ¤¶þ£º

¶Ô±ÈengģʽÒÔ¼°usrģʽϱàÒëµÄÊä³öÐÅÏ¢ºó·¢ÏÖ£¬¶þÕßcopyµÄdexÎļþ²»Í¬¡£ÈçÏ£º

usrģʽ£º

Copying: out/target/common/obj/APPS/Settings_intermediates/proguard.classes.dex

engģʽ£º

Copying: out/target/common/obj/APPS/Settings_intermediates/noproguard.classes.dex

ͨ¹ý±È½Ï¿ÉÒÔÖªµÀ£ºproguard.classes.dex±Ènoproguard.classes.dexС£¬ÕâÀïµÄproguard¾ÍÊÇ»ìÏý¡£Ò²¾ÍÊÇ˵usrģʽ¶Ô´úÂë½øÐÐÁË»ìÏý£¬´Ó¶øʹµÃusrģʽ±àÒë³öµÄSettings.apkÓëengģʽ±àÒë³öµÄ´óС²»Í¬¡£ÊÇ·ñ»áÊÇusrģʽ¶Ô´úÂë½øÐÐProGuardµ¼ÖÂÎÊÌâµÄÄØ£¿ÕâÀïÔÝʱ²»ÖªµÀ¼ÙÉè¶þÕýÈ·Óë·ñ¡£

¼ÙÉèÈý£º

usrģʽϱàÒëϵͳ¶Ô´úÂë½øÐÐProGuardʱ³öÏÖÒì³£¡£

ÑéÖ¤Èý£º

ÏÈÁ˽âÒ»ÏÂProGuardÕâ¸ö¹¤¾ß£»

ProGuard¼ò½é£º

ProGuardÊÇÒ»¸öÃâ·ÑµÄjavaÀàÎļþѹËõ£¬ÓÅ»¯£¬»ìÏýÆ÷¡£Ëü̽²â²¢É¾³ýûÓÐʹÓõÄÀ࣬×ֶΣ¬·½·¨ºÍÊôÐÔ¡£Ëüɾ³ýûÓÐÓõÄ˵Ã÷²¢Ê¹ÓÃ×Ö½ÚÂëµÃµ½×î´óÓÅ»¯¡£ËüʹÓÃÎÞÒâÒåµÄÃû×ÖÀ´ÖØÃüÃûÀà,×ֶκͷ½·¨¡£

ProGuard×÷Óãº

1.´´½¨½ô´ÕµÄ´úÂ룬¿ìËÙ×°Ôغ͸üСµÄÄÚ´æÕ¼Óá£

2.Ôö¼Ó³ÌÐòºÍ³ÌÐòʹÓõĿⱻ·´±àÒëµÄÄѶÈ

3.ɾ³ýÀ´×ÔÔ´ÎļþÖеÄûÓе÷ÓõĴúÂë ¡£

ÔÚ´óÖÂÁ˽âÁËProGuardµÄ×÷ÓÃÖ®ºó£¬»Ø¹ýÍ·À´¿´¿´lostClass.java£¬¸ÃÀàÖ÷ÒªÔÚSettings_heads.xmlÖе÷Ó㬲¢Ã»ÓÐͨ¹ýÆäËû·½Ê½µ÷Óã¬ÄѵÀÕâ±»ProGuardÎóÈÏΪÊÇûÓÐʹÓõĴúÂë¶ø¸øÓÅ»¯µôÁË£¿

´ò¿ªÔ´ÂëSettingsϵÄAndroid.mkÎļþ£¬¿ÉÒÔ¿´µ½ÒÔÏ´úÂ룺

LOCAL_PROGUARD_FLAG_FILES := proguard.flags

¼ÌÐø²é¿´µ±Ç°Â·¾¶ÏµÄproguard.flags£¬´úÂëÈçÏ£º

# Keep all Fragments in this package, which are used by reflection.
-keep class com.android.settings.*Fragment
-keep class com.android.settings.*Picker
-keep class com.android.settings.*Settings
-keep class com.android.settings.wifi.*Settings
-keep class com.android.settings.deviceinfo.*
-keep class com.android.settings.bluetooth.*
-keep class com.android.settings.applications.*
-keep class com.android.settings.inputmethod.*
-keep class com.android.settings.MasterClear
-keep class com.android.settings.MasterClearConfirm
-keep class com.android.settings.accounts.*
-keep class com.android.settings.fuelgauge.*

ÉÔÉԲ鿴ProGuardµÄÓï·¨ºóÖªµÀ£¬ÕâÑù±íʾÄÄЩÀ಻»áÍêÈ«±»ProGuard´¦Àí¡£ÏÈÔÚÕâÀï¼ÓÉÏÒ»¾ä´úÂ룺

-keep class com.android.settings.xxxx.*

ÕâÀïµÄxxxx±íʾlostClass.javaµÄ°üÃû¡£

ÔٴνøÈëÖնˣ¬Çл»µ½usrģʽϱàÒë´úÂ룬²âÊԳɹ¦£¬µ«Óм¸¸öСµÄ¹¦ÄÜ»¹ÊDz»ÄÜÕý³£Ê¹Óá£Í¨¹ýÒÔÉÏÖÁÉÙÖ¤Ã÷¼ÙÉèÈýÊÇÕýÈ·µÄ£¬¼´ÔÚProGuard¹ý³ÌÖвúÉúµÄÎÊÌâ¡£

Õ⼸¸ö²»ÄÜʹÓõÄС¹¦ÄÜ£¬¶¼ÓÐÒ»¸ö¹²Í¬µÄÌص㣬¼´µã»÷Buttonºó±¨´í£¬ÌáʾÕÒ²»µ½¶ÔÓ¦µÄ·½·¨¡£Õ⼸¸öButtonÊÇÔÚxmlÎļþÖÐÌí¼ÓonClick·½·¨µÄ£¬È磺

  <Button
    android:id="@+id/JumpButton"
    android:onClick="JumpFuction"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="1"/>

ͨ¹ý²é¿´ProGuard¹ÙÍøµÄExample¡ª¡ªA complete Android Application¿ÉÒÔÖªµÀ£¬»¹ÐèÒªÔÚproguard.flagsÖÐÌí¼ÓÒÔÏ´úÂ룺

-keepclassmembers class * extends android.content.Context {
   public void *(android.view.View);
   public void *(android.view.MenuItem);
}

¹ÙÍø¸ø³öµÄ½âÊÍÊÇ£ºWe're also keeping possible onClick handlers in custom Context extensions, since they might be referenced from XML layout files.

Ò²¾ÍÊÇ˵£ºÓеÄonClickʼþÊÇÔÚxmlÖж¨ÒåµÄ£¬ËùÒÔÔÚproguard.flagsÎļþÖÐÌí¼ÓÒÔÉÏÄÚÈÝ´Ó¶ø±£Ö¤ÕâЩonClick´¥·¢·½·¨²»»á±»ProGuardÓÅ»¯µô¡£¼ÓÉÏÒÔÉÏ´úÂ룬±àÒ룬²âÊÔ£¬Í¨¹ý£¡£¡

°¸¼þ»Ø¹Ë£º

Õû¸ö°¸¼þ¿´ËÆÆËË·ÃÔÀ룬µ«±³ºóÒþ²ØµÄÊÇAPKÕû¸ö±àÒëÁ÷³Ì¡£Ò»¿ªÊ¼¿´ËƲ»¿ÉÄܵÄÊÂÇé(usrģʽºÍengģʽ±àÒë½á¹û²»Ò»ÖÂ)£¬¾­¹ýС°×Ò»²½Ò»²½µÄ¸ú×Ùºó¾¹È»·¢ÏÖÁ˱³ºóµÄ¡°¾ªÌìÃØÃÜ¡±¡£ProGuardÊÇÒ»¸öÃâ·ÑµÄ¿ªÔ´ÏîÄ¿£¬ÓÃÒÔѹËõ¡¢ÓÅ»¯¡¢»ìÏý´úÂ룬Android Ô´Â뼯³ÉÁËproguard£¬Ä¬ÈÏ»áÔÚusrÒÔ¼°usrdebugģʽÏ¿ªÆô£¬ÕâÒ»µã¿ÉÒÔÔÚAndroidSouceCode4.0/build/core/package.mkÖÐÕÒµ½£º

ifndef LOCAL_PROGUARD_ENABLED

ifneq ($(filter user userdebug, $(TARGET_BUILD_VARIANT)),)

# turn on Proguard by default for user & userdebug build

LOCAL_PROGUARD_ENABLED :=full

endif

endif

(PS£º¸ßͨµÄÔ´ÂëÓëgoogleÔ­ÉúµÄ²î²»¶à£¬¶øMTKÔò×¢Ê͵ôÁËÕâÀïµÄLOCAL_PROGUARD_ENABLED :=full£¬¼´usr¡¢usrdebug¡¢engģʽ±àÒë³öÀ´µÄ½á¹û¶¼Ã»¾­¹ý»ìÏý¡£)

µ±È»³ýÁËProGuard»¹ÓÐÒ»¸öDexGuard¿ÉÒÔʵÏÖ¶ÔAndroidÓ¦ÓõÄÓÅ»¯Óë±£»¤£¬²»¹ýÕâ»õÊÇÊշѵÄ(×î±ãÒ˶¼Òª350 € Å·Ôª°¡¡£¡£¡£»»Ëã¹ýÀ´Òª½«½ü3000¿ìRMB¡£¡£¡£o(¨s¡õ¨t)o)¡£

×îºóÔÚ´óÈ˵ÄÃ÷²ìÇïºÁÏ£¬ÕæÏàÖÕÓÚ´ó°×¡£


 
·ÖÏíµ½
 
 


androidÈË»ú½çÃæÖ¸ÄÏ
AndroidÊÖ»ú¿ª·¢£¨Ò»£©
AndroidÊÖ»ú¿ª·¢£¨¶þ£©
AndroidÊÖ»ú¿ª·¢£¨Èý£©
AndroidÊÖ»ú¿ª·¢£¨ËÄ£©
iPhoneÏûÏ¢ÍÆËÍ»úÖÆʵÏÖ̽ÌÖ
ÊÖ»úÈí¼þ²âÊÔÓÃÀýÉè¼Æʵ¼ù
ÊÖ»ú¿Í»§¶ËUI²âÊÔ·ÖÎö
ÊÖ»úÈí¼þ×Ô¶¯»¯²âÊÔÑо¿±¨¸æ


Android¸ß¼¶Òƶ¯Ó¦ÓóÌÐò
AndroidÓ¦Óÿª·¢
Androidϵͳ¿ª·¢
ÊÖ»úÈí¼þ²âÊÔ
ǶÈëʽÈí¼þ²âÊÔ
AndroidÈí¡¢Ó²¡¢ÔÆÕûºÏ


ÁìÏÈIT¹«Ë¾ android¿ª·¢Æ½Ì¨×î¼Ñʵ¼ù
±±¾© Android¿ª·¢¼¼Êõ½ø½×
ijÐÂÄÜÔ´ÁìÓòÆóÒµ Android¿ª·¢¼¼Êõ
ijº½Ì칫˾ Android¡¢IOSÓ¦ÓÃÈí¼þ¿ª·¢
°¢¶û¿¨ÌØ LinuxÄÚºËÇý¶¯
°¬Ä¬Éú ǶÈëʽÈí¼þ¼Ü¹¹Éè¼Æ
Î÷ÃÅ×Ó Ç¶Èëʽ¼Ü¹¹Éè¼Æ