繁体   English   中英

本机代码调试在Android Studio 3中不起作用

[英]Native code debug is not working in Android Studio 3

我已经尝试了在StackOverflow上找到的所有方法,但仍然面临该问题。

我创建了一个具有本地支持的演示Android项目,向其中添加了一个库,并将所有本机代码移至该库中。

现在,我无法在本机代码中的断点处停止,本机调试器仅在SEGFAULT崩溃后才处于活动状态。

我已经将defaultPublishConfig "debug"添加到库build.gradle并且debuggable true到应用程序build.fradle 早期的本机调试已足够。 但是自从Android Studio升级以来,它不起作用。

这是完整的build.gradle文件

应用

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28

    defaultConfig {
        applicationId "com.raistlin.myapplication"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        debug {
            debuggable true
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation project(path: ':mylibrary')

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

我的图书馆

apply plugin: 'com.android.library'

android {
    compileSdkVersion 28



    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        defaultPublishConfig "debug"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        externalNativeBuild {
            cmake {
                arguments "-DANDROID_TOOLCHAIN=clang"
                cppFlags "-fexceptions", "-std=c++11", "-DJSONCPP_NO_LOCALE_SUPPORT"
                version "3.10.2"
            }
        }
    }

    buildTypes {
        debug {
            debuggable true
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

首先,为库选择检查调试变量。

由于您的build.gradle具有设置path "src/main/cpp/CMakeLists.txt" ,所以我认为它不会构建。 因此,设置targets ,重建并再次检查。

如果在构建后断点不起作用,则旧的垃圾可能会留在构建缓存中并引起问题。 在资源管理器中打开项目目录,然后手动删除构建缓存(.externalNativeBuild文件夹),然后再次构建项目。 我还删除了build文件夹,因为它在中间目录中包含.so文件,但这是可选的。

Android Studio不会清除测试设备中的库。 它们基本上被覆盖,但是根据需要手动清除它们。 文件位于/ data / app /(程序包名称)/ lib /(cpu架构)/中。
注意:设备文件资源管理器的同步菜单在lib或(cpu档案)目录下无法正确同步。 要进行同步,请选择/ data或/ data / app,然后选择同步。

NB.1如果省略了targets ,则Android Studio似乎没有建立目标。 生成的输出位于(project)/ app / build / intermediates / cmake /(flavor)/ obj /(cpu体系结构)中。 如果似乎没有任何目标,则检查设备上的文件。 他们混淆了测试结果。

NB.2 debuggable true用于发布版本以启用调试。 无需将其设置为调试版本,因为可调试标志设置为默认值。

NB.3似乎依赖版本,但即使调用clean或rebuild,Android Studio中的Gradle也无法正确清理.externalNativeBuild树,并混淆了本机代码生成配置。 我记得当时是在AS3.0左右。

NB.4我的环境是

  • Android Stuidio 3.2.1
  • 类路径'com.android.tools.build:gradle:3.2.1'
  • gradle这个-4.7-所有
  • CMake:默认(3.6.4111459)

我知道有适用于Android Studio,Gradle和CMake的较新版本,但它们存在问题,因此我选择了当前环境。 据我所知,Android Studio 3.3,gradle:3.3.0,gradle-4.10.1-在VCS(git)中均存在严重的错误。 错误的文件内容显示在编辑器中,有时会生成失败。 将CMake版本设置为3.10.x(对我而言是3.10.2)似乎也有问题。

这是我项目的一个副本,作为示例,对原始副本进行了部分修改,但可以使用。 我已经在Android Studio 3.2.1中检查了库工作中的断点。

apply plugin: 'com.android.library'

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "0.0.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        consumerProguardFiles 'proguard-rules.pro'
        externalNativeBuild {
            cmake {
                cppFlags "-std=c++11"
                arguments "-DANDROID_STL=c++_static"
                targets "sample"
            }
        }
    }

    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

更新
此处提到了目标。 指南-将Gradle链接到您的本机库-指定可选配置

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM