JNI文件夹上的C / C ++文件填充错误

时间:2015-01-12 21:09:13

标签: android eclipse android-ndk android-studio java-native-interface

背景

在过去,我创建了一个不错的Android库(链接here),允许开发人员在C / C ++世界中包含一个位图,使用它,然后将其转换回Java的世界。

问题

现在我尝试导入它,但我无法在Eclipse和Android-Studio上执行此操作。

对于Android-Studio,我可以理解,因为它还没有真正支持它,但是对于Eclipse,我已经完成了很多次并且它运行良好。我甚至根据我收集的问题制作了一个教程。

无论我做什么,这都是我得到的:

enter image description here

“Type”X'形式的许多错误无法解决。

这也导致无法创建样本运行所需的文件。

在Android Studio上,我收到此错误:

enter image description here

系统信息

Windows 8.1 64位,Eclipse 4.4.1,ADT 23.0.4.1468518,NDK r10d 64位

问题

我该如何解决?

我的图书馆出了什么问题?

另外,我应该怎么做才能让Android Studio用户导入它?

2 个答案:

答案 0 :(得分:0)

  

我的图书馆出了什么问题?

我认为您的图书馆没有任何问题。我相信这是Eclipse中ADT中的一个错误。请参阅这些AOSP错误:


  

我该如何解决?

嗯,Issue 33788: [ADT 20] Indexer support regression提供了很多变通方法。其中一些来自AOSP,其中一些来自普通用户。


  

我应该怎么做才能让Android Studio用户导入它?

抱歉,我在这里无法提供帮助,因为我不使用Android Studio。我知道Android Studio会忽略Application.mkAndroid.mk,因此您可能需要通过gradle.build添加路径(我认为这就是它的名称)。

(Eclipse下的ADT插件似乎通过解析Application.mkAndroid.mk来构建路径。

答案 1 :(得分:0)

如您所知Google宣布Android studio 1.3 RC3的新更新,最后我们获得了C ++支持。我以这种方式配置我的应用程序,一切正常。

休会这一步......

  1. 运行Android Studio 1.3 RC3并点击Import Project (Eclipse ADT, Gradle, etc.)
  2. 请参阅thisthis以配置您的应用。
  3. project structure(cmd +;在Mac OS中)将Gradle version设置为1 and Android Plugin Version leave blank < / p>

  4. 然后为您配置 app.gradle 文件

     android.ndk 
     {
    
        moduleName = "MY_MODULE_NAME" 
    
        // this is your additional include files, 
        // do this if you have subfolder inside of JNI folder
        cppFlags += "-I${file("src/main/jni/myFolder/Sources")}".toString()
        cppFlags += "-I${file("src/main/jni/myFolder/Sources/Helper")}".toString()
        cppFlags += "-I${file("src/main/jni/myFolder/Sources/Image")}".toString()
        cppFlags += "-I${file("src/main/jni/myFolder/Sources/Utils")}".toString()
    
        // add c++ 11 support
        cppFlags += "-std=c++11"
    
        // your libs
        ldLibs += ["log", "jnigraphics"]
    
        stl     = "gnustl_static"
    }
    
  5. 如果您想使用例如 cpufeatures ,则必须将其添加到JNI文件夹中。然后在 app.gradle 文件中以这种方式指定它的路径。

    cppFlags += "-I${file("src/main/jni/cpufeatures")}".toString()
    

    我的 app.gradle 文件

    apply plugin: 'com.android.model.application'
    model {
        android {
            compileSdkVersion = 21
            buildToolsVersion = "22.0.1"
    
            defaultConfig.with {
                applicationId = "com.example.testapp"
                minSdkVersion.apiLevel = 17
                targetSdkVersion.apiLevel = 22
            }
    
        }
        android.ndk {
            moduleName = "MY_MODULE_NAME" 
    
            // this is your additional include files, 
            // do this if you have subfolder inside of JNI folder
            cppFlags += "-I${file("src/main/jni/myFolder/Sources")}".toString()
            cppFlags += "-I${file("src/main/jni/myFolder/Sources/Helper")}".toString()
            cppFlags += "-I${file("src/main/jni/myFolder/Sources/Image")}".toString()
            cppFlags += "-I${file("src/main/jni/myFolder/Sources/Utils")}".toString()
    
            // add c++ 11 support
            cppFlags += "-std=c++11"
    
            // your libs
            ldLibs += ["log", "jnigraphics"]
    
            stl     = "gnustl_static"
        }
        // jni is the default dir; config this if yours is in different directory
        android.sources {
            main {
                jni {
                    source {
                        srcDirs 'src/main/jni'
                    }
                }
            }
        }
        android.buildTypes {
            release {
                isMinifyEnabled = false
                proguardFiles += file('proguard-rules.txt')
            }
        }
        android.productFlavors {
            create ("arm7") {
                ndk.abiFilters += "armeabi-v7a"
            }
            create ("arm8") {
                ndk.abiFilters += "arm64-v8a"
            }
            create ("x86-32") {
                ndk.abiFilters += "x86"
            }
            // for detailed abiFilter descriptions, refer to "Supported ABIs" @
            // https://developer.android.com/ndk/guides/abis.html#sa
            // build one including all productFlavors
            create("fat")
        }
    }
    

    我的项目gradle 文件

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    buildscript {
        repositories {
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle-experimental:0.1.0'
        }
    }
    
    allprojects {
        repositories {
            jcenter()
        }
    }
    

    我的 gradle-wrapper.properties 文件

    #Mon Jul 20 16:12:41 AMT 2015
    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-2.5-rc-1-all.zip
    

    P.S我的声誉不允许我发布图片,抱歉

相关问题