无法在Android Studio的JNI文件夹中获取源代码

时间:2015-08-19 00:39:14

标签: java android c++ android-studio android-ndk

我正在使用启用了experimental NDK plugin的Android Studio 1.3。我已将整个Box2d文件夹与Android.mk和Application.mk一起放入android studio中的jni文件夹中。 Android studio似乎完全忽略了.mk文件,因为当我更改它们时没有任何反应。无论如何,当我得到directoy not found错误时,我试图编译Box2d。 Error:(19, 42) Box2D/Collision/b2BroadPhase.h: No such file or directory

Android.mk

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= liquidfun

LOCAL_C_INCLUDES := $(LOCAL_PATH)/Box2D/Collision \
            $(LOCAL_PATH)/Box2D/Collision/Shapes \
            $(LOCAL_PATH)/Box2D/Common \
            $(LOCAL_PATH)/Box2D/Dynamics \
            $(LOCAL_PATH)/Box2D/Dynamics/Contacts \
            $(LOCAL_PATH)/Box2D/Dynamics/Joints \
            $(LOCAL_PATH)/Box2D/Dynamics/Particle \
            $(LOCAL_PATH)/Box2D/Rope



include $(BUILD_SHARED_LIBRARY)

的build.gradle

apply plugin: 'com.android.model.application'
model {
    android {
        compileSdkVersion = 21
        buildToolsVersion = "22.0.1"

        defaultConfig.with {
            applicationId = "com.mycompany.mygame"
            minSdkVersion.apiLevel = 15
            targetSdkVersion.apiLevel = 21
            versionCode = 1
            versionName = "1.0"
        }
    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles += file('proguard-rules.pro')
        }
    }
    android.ndk {
        moduleName = "liquidfun"
    }
}
def liquidFunDir = new File("${projectDir}/src/main/java/com/google/fpl/liquidfun")

task createLiquidFunDir {
    liquidFunDir.mkdirs()
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
}

任何提示都会非常感激。感谢。

2 个答案:

答案 0 :(得分:0)

您是否尝试在Windows中编译?若是,请使用" \"而不是" /"在Android.mk中 像这样:$(LOCAL_PATH)\Box2D\Common \

如果这没有帮助尝试在" build.gradle"中指定包含。像这样的文件:

android.ndk {
    moduleName ="liquidfun"
    CFlags += "-I${file("src/main/jni/Box2D/Collision")}".toString()
}

答案 1 :(得分:0)

嘿我有一个类似的问题。 gradle插件不尊重您的Android.mk文件。它会为您的项目创建一个临时的Android.mk。

在新的实验性android插件中添加Cflags:

apply plugin: 'com.android.model.application'
model {
    android {
        compileSdkVersion = 21
        buildToolsVersion = "22.0.1"

        defaultConfig.with {
            applicationId = "com.mycompany.mygame"
            minSdkVersion.apiLevel = 15
            targetSdkVersion.apiLevel = 21
            versionCode = 1
            versionName = "1.0"
        }
    }
    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles += file('proguard-rules.pro')
        }
    }
    android.ndk {
        CFlags += "-I${projectDir}/src/main/jni/Box2D/Collision".toString()
        CFlags += "-I${projectDir}/src/main/jni/Box2D/Collision/Shapes".toString()
        CFlags += "-I${projectDir}/src/main/jni/Box2D/Dynamics".toString()
        CFlags += "-I${projectDir}/src/main/jni/Box2D/Dynamics/Contacts".toString()
        CFlags += "-I${projectDir}/src/main/jni/Box2D/Dynamics/Joints".toString()
        CFlags += "-I${projectDir}/src/main/jni/Box2D/Dynamics/Particle".toString()
        CFlags += "-I${projectDir}/src/main/jni/Box2D/Rope".toString()

        cppFlags += "-I${projectDir}/src/main/jni/Box2D/Collision".toString()
        cppFlags += "-I${projectDir}/src/main/jni/Box2D/Collision/Shapes".toString()
        cppFlags += "-I${projectDir}/src/main/jni/Box2D/Dynamics".toString()
        cppFlags += "-I${projectDir}/src/main/jni/Box2D/Dynamics/Contacts".toString()
        cppFlags += "-I${projectDir}/src/main/jni/Box2D/Dynamics/Joints".toString()
        cppFlags += "-I${projectDir}/src/main/jni/Box2D/Dynamics/Particle".toString()
        cppFlags += "-I${projectDir}/src/main/jni/Box2D/Rope".toString()
        moduleName = "liquidfun"
    }
}
def liquidFunDir = new File("${projectDir}/src/main/java/com/google/fpl/liquidfun")

task createLiquidFunDir {
    liquidFunDir.mkdirs()
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
}

此外,您似乎正在编译反对sdk 10. @ ph0b(https://stackoverflow.com/a/31365158/5105445)发布了一个答案,无法运行任何<棒棒糖。

希望有所帮助