如何使用 Android studio 在发布模式下调试 Android 应用程序
How to debug the Android App in release mode using Android studio
出于某种原因,我必须 运行 我的 Android 应用程序在发布时 mode.I 必须 运行 通过代码 运行就像我们在调试模式下使用一样。当我在发布模式下 运行 时,我的断点没有命中,我在清单中添加了 android:debuggable="true"
。断点仍然没有命中。任何帮助。
提前致谢
在您的 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
是发布配置,它必须添加到 gradle 文件中的 android{} 块中,如下所示:
signingConfigs {
release {
keyAlias 'YourAppKey'
keyPassword 'somePassword'
storeFile file('appkeyfile.jks')
storePassword 'somePassword'
}
}
buildTypes {
release {
debuggable true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
快乐coding.Mark这个答案..如果它有帮助..:)
没有"release mode"。您指的是构建类型,这意味着在构建过程中采取的步骤(如缩小等)。设置 android:debuggable="true"
不会自动提供帮助,因为当您 "Run" 应用程序而不是 "Debug" 时,您不会将调试器连接到它,因此它不会因特定原因而停止。
因此,您可以将调试版本设置为以与发行版相同的方式生成,但很不清楚您的需求背后的原因是什么,我觉得您正在尝试走错路(即调试是通常不使用 ProGuard,而发布版本是,ProGuard 会更改生成的二进制文件,因此您的源代码断点无论如何都不会真正起作用。
就我而言,我已经创建了与之前版本相同的调试配置并开始调试。这意味着你必须在调试版本中也给符号构建 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'
}
}
因此它将与发布版本具有相同的符号,您可以在运行时进行调试。
我认为 是有道理的(很多情况下需要调试发布版本),所以这里是对我有用的已接受答案的细微变化:
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'
}
}
}
改编自 official docs
注意:
当我设置 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...
新来者几分钱。
如果即使在发布块中添加 debuggable true 之后,您的调试点也没有命中。
从发布块中删除以下代码。
minifyEnabled true
shrinkResources true //remove resources
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
出于某种原因,我必须 运行 我的 Android 应用程序在发布时 mode.I 必须 运行 通过代码 运行就像我们在调试模式下使用一样。当我在发布模式下 运行 时,我的断点没有命中,我在清单中添加了 android:debuggable="true"
。断点仍然没有命中。任何帮助。
提前致谢
在您的 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
是发布配置,它必须添加到 gradle 文件中的 android{} 块中,如下所示:
signingConfigs {
release {
keyAlias 'YourAppKey'
keyPassword 'somePassword'
storeFile file('appkeyfile.jks')
storePassword 'somePassword'
}
}
buildTypes {
release {
debuggable true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
快乐coding.Mark这个答案..如果它有帮助..:)
没有"release mode"。您指的是构建类型,这意味着在构建过程中采取的步骤(如缩小等)。设置 android:debuggable="true"
不会自动提供帮助,因为当您 "Run" 应用程序而不是 "Debug" 时,您不会将调试器连接到它,因此它不会因特定原因而停止。
因此,您可以将调试版本设置为以与发行版相同的方式生成,但很不清楚您的需求背后的原因是什么,我觉得您正在尝试走错路(即调试是通常不使用 ProGuard,而发布版本是,ProGuard 会更改生成的二进制文件,因此您的源代码断点无论如何都不会真正起作用。
就我而言,我已经创建了与之前版本相同的调试配置并开始调试。这意味着你必须在调试版本中也给符号构建 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'
}
}
因此它将与发布版本具有相同的符号,您可以在运行时进行调试。
我认为
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'
}
}
}
改编自 official docs
注意:
当我设置 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...
新来者几分钱。
如果即使在发布块中添加 debuggable true 之后,您的调试点也没有命中。
从发布块中删除以下代码。
minifyEnabled true
shrinkResources true //remove resources
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'