Android Studio 2.0's inline compiler does no longer recognize native code

╄→尐↘猪︶ㄣ 提交于 2019-12-24 12:33:04

问题


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

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):

  • All natives appear red in the Java code while they are properly mapped through JNI_OnLoad():

  • The whole C code is highlighted in red as Studio cannot find the includes and symbols:


...

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.

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.

My Gradle settings follow:

  • Gradle version: 2.10

  • gradle.properties:

    android.useDeprecatedNdk = true
    
  • Project's 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
    }
    
  • Module's 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'])
    }
    

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.

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.


回答1:


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.



来源:https://stackoverflow.com/questions/35343684/android-studio-2-0s-inline-compiler-does-no-longer-recognize-native-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!