2016-02-02 5 views
17

मुझे एंड्रॉइड स्टूडियो में प्रोगार्ड obfuscation सक्षम करके अपने ऐप की रक्षा करनी है। मैंने इसे लागू करने की प्रक्रिया की खोज की है लेकिन मुझे कोई स्पष्ट समाधान नहीं मिला है। जब मैं इसे आज़माता हूं, तो मुझे हमेशा एक त्रुटि मिलती है। तो क्या कोई मुझे अपने ऐप में इसे लागू करने के लिए स्पष्ट कदम बता सकता है?Android स्टूडियो में ProGuard obfuscation को सक्षम करने के लिए कैसे?

मैं निम्न चरणों के द्वारा यह कर रहा हूं:

  1. एंड्रॉयड स्टूडियो में, एक Android परियोजना को खोलने के।

  2. परियोजना दृश्य में बदलें।

  3. बदलें निम्न पंक्ति:

    minifyEnable falseminifyEnable true

  4. सेट ProGuard नियम (वैकल्पिक)

    4,1 परियोजना देखें में करने के लिए, proguard-rules.pro फ़ाइल का चयन करें।

    4.2 कुछ कक्षाओं को अपनाने के लिए ProGuard को बताने के लिए निम्न पंक्तियों में जोड़ें।

    -keepclassmembers class com.dom925.xxxx 
    { 
        public * 
    } 
    

त्रुटि है कि मैं चरणों का पालन करके हो रही हैं

Error:Execution failed for task ':app:packageRelease'. Unable to compute hash of D:\Android\Pojectname\app\build\intermediates\classes-proguard\release\classes.jar

+0

पोस्ट अपने build.gradle ताकि हम आपके निर्भरता यहाँ –

+0

के आधार पर एक और अधिक सटीक जवाब कर सकते हैं कुछ संदर्भ है http://stackoverflow.com/questions/30934729/cant-generate-signed-apk-from-android -स्टूडियो-निष्पादन-विफल-कार्य-कार्य-पैक –

+0

यहां कुछ संदर्भ है http://stackoverflow.com/questions/20885725/how-to-use-the-proguard-in-android-studio –

उत्तर

9

मैं इस समस्या पता लगा:

के लिए proguard-rules.pro खोलें अपने प्रोजेक्ट करें और इसे नीचे जोड़ें:

-dontwarn java.nio.file.Files 
-dontwarn java.nio.file.Path 
-dontwarn java.nio.file.OpenOption 
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement 

मैं मूल रूप से कैसे हल यह इस मैं 'रिलीज' मोड में मेरी अनुप्रयोग चलाने के लिए करने की कोशिश की थी और इस आदमी को यहां के समान त्रुटियों की एक गुच्छा मिला: https://github.com/square/okio/issues/144

मैं काफी पीछा किया कि वह क्या कहा है और यह तय हो गई।

आशा है कि यह दूसरों को उनके एपीके उत्पन्न करने में मदद कर सकता है!

यात्रा अधिक यहाँ विस्तार:

Error:Execution failed for task ':app:packageRelease'. > Unable to compute hash of /../AndroidStudioProjects/../classes.jar

+0

लेकिन फिर भी मुझे त्रुटि मिली दोस्त http://stackoverflow.com/questions/35150026/how-to-generate-proguard-obfuscation-in-using-android-studio –

32

एंड्रॉयड स्टूडियो में ProGuard सक्षम करने के लिए।

नीचे नमूना एंड्रॉइड स्टूडियो में डिफ़ॉल्ट ProGuard को सक्षम करने का नमूना है।

  1. जाओ अनुप्रयोग के build.gradle फाइल करने के लिए
  2. minifyEnabled सच
  3. shrinkResources सच सक्षम डिफ़ॉल्ट एक सक्षम करने के लिए APK आकार
  4. proguardFiles getDefaultProguardFile('proguard-android.txt') कम करने के लिए सक्षम करें। यदि आप अपनी खुद की प्रोजेवार्ड फ़ाइल का उपयोग करना चाहते हैं तो नीचे दिए गए नियमों का उपयोग करें।

    buildTypes { 
        release { 
         debuggable false 
         minifyEnabled true 
         shrinkResources true 
         proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
        } 
    
        debug { 
         debuggable true 
         minifyEnabled true 
         shrinkResources true 
         proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
        } 
    } 
    

एंड्रॉयड और अन्य सेटिंग्स के लिए ProGuard सेटिंग्स के साथ लिंक इन कड़ियों में उपलब्ध हैं:

this link

के माध्यम से जाना अधिक विस्तार के लिए
1
if you are building the android project with jack, then it will automatically do the shrinking, obfuscation, repackaging and multidex. 
Just add below in 

defaultConfig { 
     jackOptions { 
      enabled true 
     }   
    } 

and in build types, mention the project proguard file. 
buildTypes { 
     release { 
      // Jack build environment does not require minifyEnabled or shrinkResources. 
      // Conceptually, the jack compiler consolidates the functionality of javac, ProGuard, and dex in a single conversion step 
      //minifyEnabled = true  
      //shrinkResources true 

      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt' 
     } 

     debug { 
................... 
     } 
    } 



To disable the ProGuard obfuscation, it is required to add below line in your proguard-project.txt file 

####No obfuscation 
-dontobfuscate 
संबंधित मुद्दे