Android Studio 2.0的嵌入式编译器不再识别本机代码 [英] Android Studio 2.0's inline compiler does no longer recognize native code

查看:111
本文介绍了Android Studio 2.0的嵌入式编译器不再识别本机代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用一个包含Java和本机代码的库.

I am currently working on a library that contains Java and native code.

该版本运行良好,当客户端应用程序使用此lib时,代码执行也是如此.但是,Android Studio 2.0 beta 2的嵌入式编译器不再能够正确识别我的NDK代码(对于Studio 1.5来说是可以的):

The build works well, and so does the execution of the code when this lib is used by a client application. But the inline compiler of Android Studio 2.0 beta 2 does no longer recognize my NDK code properly (while this was OK with Studio 1.5):

  • 通过JNI_OnLoad()正确映射时,所有本机代码在Java代码中均显示为红色:
  • All natives appear red in the Java code while they are properly mapped through JNI_OnLoad():

  • 由于Studio找不到包含和符号,整个C代码以红色突出显示:


...


...

在从Android Studio 1.5切换到Studio 2.0 beta 2之前,我没有遇到这个问题.Studio能够以检测到Java本机方法和本机C代码之间的JNI_OnLoad()映射的方式对代码进行反向工程. #include<>指令等也可以.

I didn't have this problem before switching from Android Studio 1.5 to Studio 2.0 beta 2. Studio was able to reverse engineer the code in a way the JNI_OnLoad() mapping between the Java native methods and native C code was detected. #include<> directives and so on were OK too.

我不知道如何恢复此行为:我在 developer.android.com 中进行了调查因此,我对此一无所获.我也没有深入研究Studio设置.我仍在调查.

I don't know how to restore this behaviour: I investigated in developer.android.com and here in SO but I found nothing about that. I also digged into the Studio Settings with no success. I'm still investigating though.

我的Gradle设置如下:

My Gradle settings follow:

  • 版本版本:2.10

gradle.properties:

android.useDeprecatedNdk = true

  • 项目的build.gradle:

    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.0.0-beta2'
        }
    }
    
    allprojects {
        repositories {
            jcenter()
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

  • 模块的build.gradle:

    apply plugin: 'com.android.library'
    
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.2"
    
        defaultPublishConfig 'release'
        publishNonDefault true
    
        defaultConfig {
            minSdkVersion 16
            targetSdkVersion 21
        }
    
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }
    
        buildTypes {
            release {
                ndk {
                    moduleName "mylib"
                    ldLibs "log"
                }
    
                debuggable false
                jniDebuggable false
                minifyEnabled false
            }
    
            debug {
                 ndk {
                     moduleName "mylib"
                     ldLibs "log"
                     cFlags "-g"
                 }
    
                 debuggable true
                 jniDebuggable true
                 minifyEnabled false
            }
        }
    
        productFlavors {
            library {
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
    }
    

  • 由于我怀疑IDE缺少调试信息,无法正确进行反向工程,所以我也尝试为debugrelease使用完全相同的配置(-g标志打开,debuggable true ,和jniDebuggable true),但这不会改变任何内容.

    As I suspected the debug info to be missing for the IDE to do the reverse engineering properly, I also tried using exactly the same config for debug and release (with the -g flag on, debuggable true, and jniDebuggable true), but this doesn't change anything.

    编辑,20160212::研究使我认为这是Studio 2.0的NDK集成中的错误,因此我打开了

    EDIT, 20160212: researches led me to think this is a bug in the NDK integration of Studio 2.0, so I opened a Google Code ticket.

    推荐答案

    此问题已在Android Studio 2.2中修复,但仅适用于64位.项目中必须使用 CMake 替换已弃用的NDK工具链配置.

    This has been fixed in Android Studio 2.2, but only for 64 bits. The deprecated NDK toolchain must be replaced by CMake in the project configuration.

    这篇关于Android Studio 2.0的嵌入式编译器不再识别本机代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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