Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
包括外部C++;Android Studio中的库和本机NDK支持_Android_Android Studio_Gradle_Android Ndk - Fatal编程技术网

包括外部C++;Android Studio中的库和本机NDK支持

包括外部C++;Android Studio中的库和本机NDK支持,android,android-studio,gradle,android-ndk,Android,Android Studio,Gradle,Android Ndk,我试图利用Android Studio中的(实验性)原生NDK支持。我刚开始和格雷德尔一起工作。我试图构建的项目使用外部库,这些库在编译项目时将被编译为静态库,然后在项目中使用。我该怎么做 详细说明,在默认代码> SRC/MN/JNI中有C++代码,编译正确,在 JNI文件夹下可以在Android Studio中正确地看到。该项目使用外部C++静态库——有些是编译的,有些不是。我需要正确地构建项目和库,并尽可能地看到代码 首先,有没有一种方法可以使用Android.mk文件?它们已经可以从以前的

我试图利用Android Studio中的(实验性)原生NDK支持。我刚开始和格雷德尔一起工作。我试图构建的项目使用外部库,这些库在编译项目时将被编译为静态库,然后在项目中使用。我该怎么做

详细说明,在默认代码> SRC/MN/JNI<代码>中有C++代码,编译正确,在 JNI文件夹下可以在Android Studio中正确地看到。该项目使用外部C++静态库——有些是编译的,有些不是。我需要正确地构建项目和库,并尽可能地看到代码

首先,有没有一种方法可以使用Android.mk文件?它们已经可以从以前的方案中导入库,但现在似乎被忽略了

我曾尝试在android.source中使用
srcDirs
添加库的路径,但奇怪的是,有些路径没有从编译器中找到,编译停止。代码如下:

    android.sources {
        main {
            jni {
                source {
                    srcDirs += ["/../../../libPdf/"]

//                  aes library
                    srcDirs += ["/../../../libs/aes/include", "/../../../libs/aes"]

//                  jpeg library
                    srcDirs += ["/../../../libPdf/platform/Android", "/../../../libs/jpeg/jpeg-9"]
                }
            }
        }
    }
我还尝试将库添加为单独的模块,然后在项目
build.gradle
(我在本示例中看到了这一个:)中编译它们中的每一个,但即使我为库创建了
build.gradle
文件,也会出现此错误:

错误:找不到名为“default”的配置

我不知道库是否需要.iml文件,我没有,也不知道如何创建。我试图改变一个现有的,并把它放在图书馆,但同样的错误发生了。 以下是来自项目build.gradle的代码:

apply plugin: 'com.android.model.library'
apply plugin: 'maven'

def jpeg_sdk_path = file(project(':jpeg').projectDir).absolutePath + "/jpeg-9"

model {

    android.buildTypes {
        release {
            consumerProguardFiles += file('proguard-project.txt')
        }
    }


    android.ndk {
        moduleName = "native"

        cppFlags += "-I${jpeg_sdk_path}".toString()
        ldLibs += ["jpeg"]

    }

    android {
        compileSdkVersion = 23
        buildToolsVersion = "21.1.2"

        defaultConfig.with {
            minSdkVersion.apiLevel = 14
            targetSdkVersion.apiLevel = 23
        }


        lintOptions.with {
            disable 'MissingTranslation'
        }

        //copy resources and stuff tasks

    }


}
dependencies {
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile files('libs/jsoup-1.7.3.jar')
    compile project(':jpeg')
}
这是设置。gradle:

include ':libPDF'
include ':PDFViewer'
include ':jpeg'
project(':jpeg').projectDir = new File(settingsDir, '/../../../libs/jpeg')
还有更多的库要包含,但我现在只想导入一个——jpeg,看看它是否正常工作。我现在正在尝试制作本地模块,并以某种方式将它们从gradle连接到其他地方的代码。我仍然收到相同的错误-似乎找不到
build.gradle
文件

有什么建议吗?提前谢谢

编辑: 我设法编译了整个程序,但现在我发现了链接器错误。以下是该项目的build.gradle(缩写版本):

apply plugin: 'com.android.model.library'
apply plugin: 'maven'

def jpeg_sdk_path = file(project(':jpeg').projectDir).absolutePath + "/../../../../../../../libs/jpeg/jpeg-9"
//other defs of paths

model {

android.buildTypes {
    release {
        minifyEnabled = false
        consumerProguardFiles += file('proguard-project.txt')
    }
    debug {
        minifyEnabled = false
        consumerProguardFiles += file('proguard-project.txt')
    }
}

android.sources {
    main {
        jni {
            source {
                srcDirs += ["src/main/jni/"]
                //lcms2
                srcDirs += [lcms2_out_path + "/src"]


                //freetype library
                include aes_path + "/aes_modes.c"
                include aes_path + "/aescrypt.c"
                include aes_path + "/aeskey.c"
                include aes_path + "/aestab.c"

 //                  jbig2 library
                srcDirs += [jbig2_path + "/src/jbig2", jbig2_path + "/include"]

//                  sfntly library
                include sfntly_path + "/sample/chromium/subsetter_impl.cc"
                //many other includes here

//                  jpeg library
                srcDirs += [ jpeg_main_path + "/../../../../../../../libPdf/platform/Android"]

                include jpeg_sdk_path + "/jaricom.c"
                include jpeg_sdk_path + "/jcapimin.c"
                //many other includes here

                //native libpdf library
                include libpdf_path+ "/PdfCatalog.cpp"
                //many other includes here

                //openssl library
                srcDirs += [openssl_path + "/lib/Android/armeabi-v7a/include"]
            }
        }

        jniLibs{
            source{
                srcDirs += ['/src/main/libs']
                srcDirs += [freetype_path + '/platform/Android/obj/local']
                srcDirs += [libpdf_path]
            }
        }

        resources.source.srcDirs += ['src/main/res']
    }


}

android.ndk {
    moduleName = "native"

    CFlags += "-I${openjpeg_path}/prebuilt/armeabi-v7a/include".toString() //figure out how to include for other flavors
    CFlags += "-I${jpeg_main_path}/../../../../../../../libPdf/platform/Android".toString()
    CFlags += "-I${jpeg_sdk_path}".toString()
    //other CFlags here
    CFlags += "-DSFNTLY_NO_EXCEPTION"
    CFlags += "-DU_STATIC_IMPLEMENTATION"
    cppFlags += CFlags

    abiFilters += "armeabi-v7a"
    ldFlags += "-L${freetype_src_path }/../platform/Android/obj/local/armeabi-v7a".toString()
    ldLibs += ["log", "android", "EGL", "GLESv1_CM", "ft2"]
    //other ldFlags and ldLibs - for the static .a libraries only
    stl = "gnustl_static"

}

compileOptions.with {
    sourceCompatibility=JavaVersion.VERSION_1_7
    targetCompatibility=JavaVersion.VERSION_1_7
}

android {
    compileSdkVersion = 23
    buildToolsVersion = "21.1.2"

    defaultConfig.with {
        minSdkVersion.apiLevel = 14
        targetSdkVersion.apiLevel = 23
    }

    lintOptions.with {
        disable 'MissingTranslation'
        abortOnError = false
    }

    //tasks for moving resources and stuff here
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.0.0'
compile files('libs/jsoup-1.7.3.jar')
compile project(':jpeg')
compile project(':freetype')
compile project(':lcms2')
compile project(':jbig2')
compile project(':aes')
compile project(':openjpeg')
compile project(':sfntly')
}
现在我遇到了很多这样的错误:

错误:(737,-1)渐变:未定义对“AndroidBitmap_getInfo”的引用

我想我知道为什么我会得到这个-我应该使用其他东西,而不是
include
,来将单个文件添加到源代码集中


我现在的问题是:如何将单个文件添加到源集中,以便编译器和链接器可以使用它们?

问题尚不清楚。您在哪个模块中有错误?哪个是有错误的配置?模块是“jpeg”-它是空的,唯一一行代码是“apply plugin:“java”。我创建了一个新的本机配置,并且正在使用它(就像在官方教程中一样)。不管怎么说,我已经完成了编译工作。我有链接器问题。我很快会更新这个问题。谢谢你的帮助!文档明确指出,“纯本机”模块不受支持(目前?),对我来说,
include
语句在
main.jni.sources
中没有任何效果。我更喜欢使用传统的Android.mk方法,现在它仍然更灵活,更受支持。诀窍是禁用内置的gradle编译和链接任务,并添加手动
buildNative
任务。问题尚不清楚。您在哪个模块中有错误?哪个是有错误的配置?模块是“jpeg”-它是空的,唯一一行代码是“apply plugin:“java”。我创建了一个新的本机配置,并且正在使用它(就像在官方教程中一样)。不管怎么说,我已经完成了编译工作。我有链接器问题。我很快会更新这个问题。谢谢你的帮助!文档明确指出,“纯本机”模块不受支持(目前?),对我来说,
include
语句在
main.jni.sources
中没有任何效果。我更喜欢使用传统的Android.mk方法,现在它仍然更灵活,更受支持。诀窍是禁用内置的gradle编译和链接任务,并添加手动
buildNative
任务。