作者:白云下6_136 | 来源:互联网 | 2023-05-19 16:24
目前我正在开发一款基于第三方代码的Android应用.我开始设置断点来理解代码,很快就遇到了问题.突然间我无法让Android Studio停在断点处.
我尝试在onCreate
方法中设置断点,在按钮内OnClickListener
- 没有任何效果.现在我发现它唯一可以工作的地方是app模块.由于项目在app模块中只有一个活动类,而其他所有内容都在库模块中提供,实际上我根本无法调试.
我假设AndroidManifest.xml中有一些错误,或者更有可能在build.gradle文件中.当我刚从Eclipse切换到Android Studio时,所有这些gradle对我来说都是新手.
如果我在应用程序运行时将鼠标悬停在库断点上,它会告诉我"在行中找不到可执行代码[...]".我认为这是我的问题的原因,但我不知道如何解决它.
build.gradle中的条目中是否有任何"常见的嫌疑人"可能导致我的问题?
我已经清理了我的项目并使缓存失效但没有成功.我甚至尝试了
在库模块中为内部片段添加条目的建议.
编辑:我正在使用最新版本的Android Studio(从2月18日开始的1.1.0版),它应该具有修复过的类似错误.
app模块中build.gradle的内容:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion Integer.parseInt(project.MIN_SDK)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
signingConfigs {
release {
keyAlias 'xxx'
keyPassword 'xxx'
storeFile file('xxx')
storePassword 'xxx'
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.release
debuggable false
jniDebuggable false
zipAlignEnabled true
}
debug {
minifyEnabled false
debuggable true
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':firebase_plugin')
}
和库模块的build.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 19
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion Integer.parseInt(project.MIN_SDK)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
buildTypes {
release {
minifyEnabled true
zipAlignEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
minifyEnabled false
debuggable true
}
}
productFlavors {
}
}
dependencies {
// Facebook SDK
compile project(':facebook')
// Used for StringUtils
compile files('libs/commons-lang3-3.3.2.jar')
// Bug tracking
compile files('libs/bugsense-3.6.1.jar')
compile fileTree(include: ['*.jar'], dir: 'libs')
//Google Play Services - For Google Maps
compile('com.google.android.gms:play-services:5.0.89') {
exclude group: 'com.google.android', module: 'support-v4'
}
// Support Library.
compile 'com.android.support:support-v13:18.0.+'
compile('com.android.support:appcompat-v7:19.1.0') {
exclude group: 'com.google.android', module: 'support-v4'
}
// Volley - Networking library from google.
compile('com.mcxiaoke.volley:library:1.0.0') {
exclude group: 'com.google.android', module: 'support-v4'
}
// Has is own support library in it so need to exclude it so no TOP_LEVEL_EXCEPTION will occur.
compile('de.greenrobot:greendao:1.3.0') {
exclude group: 'com.google.android', module: 'support-v4'
}
// Firebase
compile('com.firebase:firebase-simple-login:1.4.2') {
exclude group: 'com.android.support', module: 'support-v4'
}
// Super Toast
compile('com.github.johnpersano:supertoasts:1.3.4@aar') {
exclude group: 'com.android.support', module: 'support-v4'
}
// Croping images
compile('com.soundcloud.android:android-crop:0.9.10@aar') {
exclude group: 'com.android.support', module: 'support-v4'
}
compile('com.github.chrisbanes.actionbarpulltorefresh:library:0.9.9') {
exclude group: 'com.android.support', module: 'support-v4'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':firebase_plugin')
}
1> droidpl..:
如本期注释中所述,minifyEnabled false
在调试版本中设置是最佳实践.通过在app模块中设置此变量,您将禁用整个proguard构建过程.它在优化发布版本时很有用,但如果您正在测试和开发,则会出现一些问题.
请记住,断点不适用于空行或注释.
2> olik79..:
我解决了它,虽然我还没有完全理解它.问题是ProGuard仍然像@Feantury建议的那样活跃.我不知道为什么会出现这种情况,因为我已经minifyEnabled false
在每个build.gradle中指定了我可以想象的位置,但它似乎没有任何效果.
就在几分钟前我遇到了崩溃,我看到堆栈跟踪中的线条看起来像这样:
java.lang.NullPointerException
at com.example.MyClass(Unknown Source)
...
这让ProGuard成为我的头号嫌疑人.经过一番搜索后,我找到了另一个SO问题来处理未知来源问题.我尝试了启用ProGuard的调试建议解决方案,并且它有效!
只需将以下行添加到proguard-rules.txt:
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
上帝保佑你我的朋友,我花了我的时间来解决一个该死的问题,最后你非常好的问题和答案帮助我看到地平线上的光芒:)问候
3> smoothumut..:
除了olik79的答案之外,我想补充一点,这两行会让你的应用程序在片段中击中断点.否则它可能会破坏碎片
-keep public class * extends android.support.v4.** {*;}
-keep public class * extends android.app.Fragment
这是我对sdk\tools\proguard中proguard-android.txt的完整编辑
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontwarn android.support.**
-keep class !android.support.v7.internal.view.menu.**,android.support.** {*;}
-ignorewarnings
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
-keep public class * extends android.support.v4.** {*;}
-keep public class * extends android.app.Fragment
谢谢你,所以,所以,所以,所以,那么多
你救了我的命!!!!!非常感谢你如此如此如此如此如此!
这样的快乐让人开心:)