Android Studio在release模式下设置debuggable

在手机上run了一个release版本的app发现不能进行debug

Android Studio在release模式下设置debuggable_第1张图片

只能看到手机,看不到app的进程

于是想到在AndroidManifest文件设置debuggable但是却提示了这个

Android Studio在release模式下设置debuggable_第2张图片

详细信息是

Avoid hardcoding the debug mode; leaving it out allows debug and release builds to automatically assign one less... (Ctrl+F1)
Inspection info: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.  Issue id: HardcodedDebugMode

大概意思是不要在AndroidManifest设置debuggable,如果设置了,在编译时,release模式自动会设置成false,debug模式会被设置成true。那么在哪里设置呢,思考了一下,编译相关的配置大都在gradle里面,于是去gradle文件中找了一下,就找到了buildTypes设置项

添加buildTypes->release中的debuggable属性即可

Android Studio在release模式下设置debuggable_第3张图片

然后运行一下,就可以debug了。

你可能感兴趣的:(Android)