判斷android是否是debug


1.使用BuildConfig.DEBUG,這個在住modul里面是有效的,但是在有依賴庫里面使用就會一直返回false,可以通過下面的方法解決:在library的build.gradle中添加以下代碼

gradle.startParameter.getTaskNames().each { task ->  
        println("task: " + task)  
        //library里 BuildConfig.DEBUG默認一直是flase;所以需要自定義  
        if(task.contains("Debug")){  
            android{  
                defaultPublishConfig "debug"  
            }  
  
        }else if(task.contains("Release")){  
            android{  
                defaultPublishConfig "release"  
            }  
        }  
    }  
2.不需要使用BuildConfig.DEBUG
public boolean isDebug(Context context){  
  boolean isDebug = context.getApplicationInfo()!=null&&  
          (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)!=0;  
  return isDebug;  
}  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM