Android Studio 的调试器不会在库模块中的断点处停止 [英] Android Studio's debugger not stopping at breakpoints within library modules

查看:71
本文介绍了Android Studio 的调试器不会在库模块中的断点处停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在开发基于第三方代码的 Android 应用.我开始设置断点来理解代码,很快就遇到了问题.突然间,我再也无法让 Android Studio 在断点处停止.

At the moment I'm developing an Android app that is based on third party code. I started to set breakpoints for understanding the code and soon ran into a problem. Suddenly I couldn't get Android Studio to stop at breakpoints anymore.

我试图在 onCreate 方法中设置断点,在按钮的 OnClickListener s 中 - 没有任何效果.现在我发现它唯一工作的地方是在 app 模块内.由于该项目在应用模块中只有一个活动类,而其他所有内容都在库模块中提供,因此我根本无法调试.

I tried to set the breakpoints within onCreate methods, within buttons' OnClickListeners - nothing worked. Now I found out that the only place it works is inside the app module. As the project just has one single activity class in the app module and everything else is provided within library modules in fact I can't debug at all.

我认为 AndroidManifest.xml 或 build.gradle 文件中可能有问题.当我刚刚从 Eclipse 切换到 Android Studio 时,所有这些 gradle 东西对我来说都很新.

I assume there's something wrong in the AndroidManifest.xml or more likely in the build.gradle file. As I just switched from Eclipse to Android Studio, all of this gradle stuff is pretty new to me.

如果我在应用程序运行时将鼠标悬停在库断点上,它会告诉我在行...处找不到可执行代码 [is]".我认为这是我的问题的原因,但我不知道如何解决它.

If I hover over a library breakpoint while the app is running, it tells me that "no executable code [is] found at line ...". I assume this is the cause of my problem, but I have no idea about how to fix it.

在 build.gradle 中的条目中是否有任何常见的嫌疑人"可能会导致我的问题?

Are there any "usual suspects" among the entries in build.gradle that could cause my problem?

我已经清理了我的项目并使缓存无效但没有成功.我什至尝试了在库模块中为里面的片段添加 条目的建议.

I already did clean my project and invalidated the cache without success. I even tried the suggestion to add <activity> entries inside the library module for the fragments inside.

编辑:我使用的是最新版本的 Android Studio(2 月 18 日发布的 1.1.0 版),该版本应该修复了前段时间存在的类似错误.

Edit: I'm using the most current version of Android Studio (version 1.1.0 from February 18) which should have the similar bug fixed that existed some time ago.

app模块中build.gradle的内容:

The contents of build.gradle in the app module:

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:

And the build.gradle of library module:

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')
}

推荐答案

如本期评论中所述,在调试版本中设置 minifyEnabled false 是最佳实践.通过在 app 模块中设置此变量,您将禁用整个 proguard 构建过程.它在优化发布版本时很有用,但在测试和开发时会出现一些问题.

As stated in the comments of this issue, setting minifyEnabled false in the debug build is the best practice. By setting this variable in the app module you are disabling the entire proguard build process. It is useful when optimizing the release build, but gives some problems if you are testing and developing.

这篇关于Android Studio 的调试器不会在库模块中的断点处停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆