【发布时间】:2015-11-19 11:17:02
【问题描述】:
出于某种原因,我必须在发布模式下运行我的 Android 应用程序。在运行应用程序时,我必须像在调试模式下一样运行代码。当我在发布模式下运行时,我的断点没有命中,我在清单中添加了android:debuggable="true"。断点仍然没有命中。任何帮助。
提前致谢
【问题讨论】:
标签: android android-studio android-debug
出于某种原因,我必须在发布模式下运行我的 Android 应用程序。在运行应用程序时,我必须像在调试模式下一样运行代码。当我在发布模式下运行时,我的断点没有命中,我在清单中添加了android:debuggable="true"。断点仍然没有命中。任何帮助。
提前致谢
【问题讨论】:
标签: android android-studio android-debug
在您的 gradle 文件中,您必须在发布风格中添加可调试功能。
buildTypes {
release {
debuggable true
minifyEnabled false
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
debuggable true
minifyEnabled false
applicationIdSuffix '.debug'
}
}
signingConfig 是发布配置,必须在 android{} 块的 gradle 文件中添加,如下所示:
signingConfigs {
release {
keyAlias 'YourAppKey'
keyPassword 'somePassword'
storeFile file('appkeyfile.jks')
storePassword 'somePassword'
}
}
【讨论】:
release { signingConfig signingConfigs.debug } 以使用您的调试证书签署发布版本。
在我的例子中,我创建了与之前版本相同的调试配置并开始调试。这意味着您必须在构建 gradle 中也提供调试版本中的符号构建。
signingConfigs {
config {
keyAlias 'abc'
keyPassword 'xyz'
storeFile file('<<KEYSTORE-PATH>>.keystore')
storePassword 'password'
}
}
buildTypes {
debug {
debuggable true
signingConfig signingConfigs.config
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
所以它和release build有相同的标志,你可以在它运行时调试。
【讨论】:
buildTypes {
release {
debuggable true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
快乐的编码。标记这个答案..如果它有帮助.. :)
【讨论】:
没有“发布模式”。您指的是构建类型,这意味着在构建过程中采取的步骤(如缩小等)。设置android:debuggable="true" 不会自动提供帮助,因为当您“运行”应用程序而不是“调试”时,您不会将调试器连接到它,因此它不会因特定原因而停止。
因此,您可以将调试版本设置为以与发布相同的方式生成,但不清楚您需要的原因是什么,我感觉您正在尝试走错路(即调试通常不是使用 ProGuard,而发布版本是并且 ProGuard 会更改生成的二进制文件,因此您从源代码中的断点无论如何都不会真正起作用。
【讨论】:
我认为Marcin's argument above 是有道理的(就像在某些情况下需要调试发布版本一样),所以这里有一些对我有用的公认答案:
android {
...
buildTypes {
release {
shrinkResources false # this was key
minifyEnabled false # seems that it can't be set to true if shrinkResources is false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
注意:
当我设置minifyEnabled true时,应用启动时出现以下崩溃:
java.lang.RuntimeException: Unable to instantiate application co.mycompany.app.MyApp: java.lang.ClassNotFoundException: Didn't find class "co.mycompany.app.MyApp" on path: DexPathList...
【讨论】:
release 版本时进行调试。
minifyEnabled 和shrinkResources 标志需要具有相同的值)
新人只需几分钱。
如果即使在发布块中添加 debuggable true 之后,您的调试点也没有命中。
从发布块中删除以下代码。
minifyEnabled true
shrinkResources true //remove resources
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
【讨论】: