JNI文件夹上的C / C ++文件夹中填写错误 [英] C/C++ file on JNI folder filled with errors
问题描述
背景
过去,我做了一个不错的Android库(链接和 来配置你的应用程序。
在项目结构
(在Mac OS中的cmd +;)设置 Gradle版本
到 1
code>和Android Plugin Version 留空
然后为您配置 app.gradle 文件
android.ndk
{
moduleName =MY_MODULE_NAME
//这是您的附加包含文件
//如果您在JNI文件夹内有子文件夹
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()
//添加c ++ 11支持
cppFlags + =-std = c ++ 11
//你的libs
ldLibs + = [log,jnigraphics]
stl =gnustl_static
}
如果要使用例如 cpufeatures ,您必须添加它到你的JNI文件夹。然后在 app.gradle 文件中以这种方式指定路径。
cppFlags + = - 我$ {file(src / main / jni / cpufeatures)}。toString()
我的 app.gradle 文件
应用插件:'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
//这是您的附加包含文件
//如果您在JNI文件夹内有子文件夹
cppFlags + =-I $ {file( src / main / jni / myFolder / Sources)}。toString()
cppFlags + =-I $ {file(src / main / jni / myFolder / Sources / Helper)}toStr ing()
cppFlags + =-I $ {file(src / main / jni / myFolder / Sources / Image)}toString()
cppFlags + =-I $ {file (src / main / jni / myFolder / Sources / Utils)}。toString()
//添加c ++ 11支持
cppFlags + =-std = c ++ 11
//你的libs
ldLibs + = [log,jnigraphics]
stl =gnustl_static
}
// jni是默认目录;如果你的目录是不同的目录,你可以配置这个
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
}
//详细的abiFilter描述,请参阅支持的ABI@
// https://developer.android.com/ndk/guides/ abis.html#sa
//构建一个包括所有productFlavors
create(fat)
}
我的项目毕业文件
//顶级构建文件,您可以在其中添加所有子项目/模块通用的配置选项。
buildscript {
repositories {
jcenter()
}
依赖关系{
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
PS我的声誉不允许我发布图像,抱歉
Background
In the past, I've made a nice Android library (link here) that allows the developers to contain a bitmap within C/C++ world, play with it, and later convert it back to Java's world.
The problem
Now that I try to import it, I fail to do so on both Eclipse and Android-Studio.
For Android-Studio, I can understand, since it doesn't really support it well yet, but for Eclipse, I've done it many times and it worked fine. I've even made a tutorial based on the problems I've collected over time.
No matter what I do, this is what I get:
A lot of errors in the form of "Type 'X' could not be resolved" .
This also leads to failure in creating the files the sample needs in order to run.
On Android Studio, I get this error:
System Info
Windows 8.1 64bit, Eclipse 4.4.1, ADT 23.0.4.1468518, NDK r10d 64bit
The question
How do I fix it?
What is wrong with my library?
Also, what should I do in order to allow Android Studio users import it?
As you know Google announced the new update of Android studio 1.3 RC3, and finally we get C++ support. I configure my app this way and everything working just fine.
Fallow this steps...
- Run Android Studio 1.3 RC3 and click
Import Project (Eclipse ADT, Gradle, etc.)
- See this and this to configure your app.
In
project structure
(cmd + ; in Mac OS) setGradle version
to1
and Android Plugin Version
leave blank
Then configure you app.gradle file
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" }
if you want to use for example cpufeatures , you must add it to your JNI folder. Then in app.gradle file specify path to it in this way .
cppFlags += "-I${file("src/main/jni/cpufeatures")}".toString()
My app.gradle file
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")
}
}
My project gradle file
// 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()
}
}
My gradle-wrapper.properties file
#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 my reputation is not allowing me to post images, sorry
这篇关于JNI文件夹上的C / C ++文件夹中填写错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!