6

रूप Getting "debuggable" value of androidManifest from code? से देखें, वहाँ जाँच के दो विकल्प हैं अगर निर्माण डीबग करने योग्य है:BuildConfig.DEBUG बनाम ApplicationInfo.FLAG_DEBUGGABLE

1.) BuildConfig.DEBUG झंडा

if (BuildConfig.DEBUG)` 

2.) ApplicationInfo। FLAG_DEBUGGABLE

if (0 != (getContext().getApplicationInfo().flags & 
    ApplicationInfo.FLAG_DEBUGGABLE)) 

क्या वे दो समान हैं, या वे अलग हैं? कब उपयोग करें?

उत्तर

5

वे समान नहीं हैं।

कई buildType एस हो सकते हैं, लेकिन debug और release अनिवार्य हैं। BuildConfig.DEBUGtrue होगा यदि वर्तमान में चयनित प्रकार का चयन debug है, अन्यथा यह false होगा (नीचे बहिष्करण केस देखें)।

ApplicationInfo.FLAG_DEBUGGABLE निम्नलिखित से मेल खाती है:

 

    buildTypes { 
     debug { 
      debuggable true 
     } 

     ... 
    } 
 

अब, ApplicationInfo.FLAG_DEBUGGABLEtrue हो जाएगा।

इस प्रकार, आप निष्कर्ष निकाल सकते हैं, कि आप निम्न कर सकता है:

 

    buildTypes { 
     debug { 
      debuggable false 
     } 

     ... 
    } 
 

दिलचस्प है, हालांकि आप debug निर्माण प्रकार में हैं, BuildConfig.DEBUGfalse बन जाएगा।

+0

डीबग का उपयोग क्या है जहां डिबगबल गलत है? – Elye

+0

मैं ऐसे मामले को याद नहीं कर सकता, क्षमा करें। – azizbekian

2

यहां एक अच्छा लेख मिला: http://tekeye.biz/2013/android-debug-vs-release-build

ने इसका भी परीक्षण किया। अगर हम प्रकट आवेदन पर android:debuggable="false" या android:debuggable="true" मजबूर है, यह चेतावनी देगा:

Avoid hardcoding the debug mode; leaving it out allows debug and release builds to automatically assign one less... 

It's best to leave out the android:debuggable attribute from the manifest. If you do, then the tools will automatically insert android:debuggable=true when building an APK to debug on an emulator or device. And when you perform a release build, such as Exporting APK, it will automatically set it to false. 
If on the other hand you specify a specific value in the manifest file, then the tools will always use it. This can lead to accidentally publishing your app with debug information. 

मैं निष्कर्ष निकालना होता है, डिफ़ॉल्ट स्थिति में android:debuggable बदल रहा है, जो कुछ उचित नहीं है द्वारा BuildConfig.DEBUG रूप में एक ही व्यवहार करते हैं ApplicationInfo.FLAG_DEBUGGABLE, जब तक ओवरराइड।

BuildConfig.DEBUG को, ApplicationInfo.FLAG_DEBUGGABLE डीबग बिल्ड के लिए जाँच करने के लिए, एक कम निर्भर मॉड्यूल में के रूप में, यह माता पिता के मॉड्यूल के BuildConfig.DEBUG उपयोग नहीं कर सकते हैं, और एक मान अलग हो सकता एक और अधिक विश्वसनीय तरीका है की तुलना करें।

उदा। ऐप MyLib मॉड्यूल का उपयोग करें। ऐप का BuildConfig.DEBUG गलत हो सकता है, लेकिन MyLib BuildConfig.DEBUG सत्य हो सकता है। इसलिए ApplicationInfo.FLAG_DEBUGGABLE

0

मेरा अनुभव यह है कि BuildConfig.DEBUG हमेशा debuggable ग्रेडल फ़ाइल में विशेषता विशेषता से जुड़ा हुआ है।

buildTypes { 
    debug { 
     debuggable true 
    } 
    debug { 
     debuggable false 
    } 

    ... 
} 

documentation भी इस का समर्थन करता है:

  • बूलियन डीबग - अगर निर्माण डीबग करने योग्य है।

getContext().getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE संभावना है, तो निर्माण Gradle निर्माण प्रणाली से पहले डीबग करने योग्य था और एंड्रॉयड स्टूडियो 2015

आसपास ग्रहण की जगह उपयोग BuildConfig.DEBUG क्योंकि यह एक स्थिर जो इस्तेमाल किया जा सकता करने के लिए हल करता है यह निर्धारित करने के लिए एक ही रास्ता था कोड अनुकूलित करने के लिए संकलन के दौरान।

संबंधित मुद्दे