指定armeabi-v7a,但jni继续构建x86_64

时间:2019-07-02 08:33:53

标签: android android-ndk android-gradle

我正在通过使用第三个库来执行jni,其中jni库:libLivenessDetectorJni.so依赖liblivenessdetector.so(仅armeabi-v7a中的第三个库)。

我仅在gradle的armeabi-v7a下指定abi构建:

externalNativeBuild {
            cmake {
            cppFlags "-std=c++11 -frtti -fexceptions"
            abiFilters "armeabi-v7a"
            }
        }

但是在构建armeabi-v7a(成功)之后,它继续构建x86_64(失败),为什么?

> Task :common-silent:externalNativeBuildDebug
Build LivenessDetectorJni armeabi-v7a
[1/2] Building CXX object CMakeFiles/LivenessDetectorJni.dir/LivenessDetectorJni.cpp.o
[2/2] Linking CXX shared library /home/jnitest/common-silent/build/intermediates/cmake/debug/obj/armeabi-v7a/libLivenessDetectorJni.so

> Task :common-silent:mergeDebugJniLibFolders
> Task :common-silent:transformNativeLibsWithMergeJniLibsForDebug
> Task :common-silent:transformNativeLibsWithStripDebugSymbolForDebug
> Task :common-silent:transformNativeLibsWithIntermediateJniLibsForDebug

> Task :app:externalNativeBuildDebug FAILED
Build LivenessDetectorJni x86_64
ninja: error: '/home/jnitest/common-silent/src/main/jniLibs/x86_64/liblivenessdetector.so', needed by '/homejnitest/app/build/intermediates/cmake/debug/obj/x86_64/libLivenessDetectorJni.so', missing and no known rule to make it

失败:构建失败,并出现异常。

谁可以帮助我进行配置?谢谢。

顺便说一句,在删除所有abiFilters并保存了构建日志之后,我发现jni被编译了2次。为什么?

cat log | grep LivenessDetectorJni --color
Build LivenessDetectorJni x86_64
[1/2] Building CXX object CMakeFiles/LivenessDetectorJni.dir/LivenessDetectorJni.cpp.o
[2/2] Linking CXX shared library /home/jnitest/common-silent/build/intermediates/cmake/debug/obj/x86_64/libLivenessDetectorJni.so
Build LivenessDetectorJni x86
[1/2] Building CXX object CMakeFiles/LivenessDetectorJni.dir/LivenessDetectorJni.cpp.o
[2/2] Linking CXX shared library /home/jnitest/common-silent/build/intermediates/cmake/debug/obj/x86/libLivenessDetectorJni.so
Build LivenessDetectorJni arm64-v8a
[1/2] Building CXX object CMakeFiles/LivenessDetectorJni.dir/LivenessDetectorJni.cpp.o
[2/2] Linking CXX shared library /home/jnitest/common-silent/build/intermediates/cmake/debug/obj/arm64-v8a/libLivenessDetectorJni.so
Build LivenessDetectorJni armeabi-v7a
[1/2] Building CXX object CMakeFiles/LivenessDetectorJni.dir/LivenessDetectorJni.cpp.o
[2/2] Linking CXX shared library /home/jnitest/common-silent/build/intermediates/cmake/debug/obj/armeabi-v7a/libLivenessDetectorJni.so
Build LivenessDetectorJni x86_64
[1/2] Building CXX object CMakeFiles/LivenessDetectorJni.dir/LivenessDetectorJni.cpp.o
[2/2] Linking CXX shared library /home/jnitest/app/build/intermediates/cmake/debug/obj/x86_64/libLivenessDetectorJni.so
Build LivenessDetectorJni x86
[1/2] Building CXX object CMakeFiles/LivenessDetectorJni.dir/LivenessDetectorJni.cpp.o
[2/2] Linking CXX shared library /home/jnitest/app/build/intermediates/cmake/debug/obj/x86/libLivenessDetectorJni.so
Build LivenessDetectorJni arm64-v8a
[1/2] Building CXX object CMakeFiles/LivenessDetectorJni.dir/LivenessDetectorJni.cpp.o
[2/2] Linking CXX shared library /home/jnitest/app/build/intermediates/cmake/debug/obj/arm64-v8a/libLivenessDetectorJni.so
Build LivenessDetectorJni armeabi-v7a
[1/2] Building CXX object CMakeFiles/LivenessDetectorJni.dir/LivenessDetectorJni.cpp.o
[2/2] Linking CXX shared library /home/jnitest/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libLivenessDetectorJni.so

如果我使用abiFilters,则日志更改为:

cat log | grep LivenessDetectorJni --color
Build LivenessDetectorJni armeabi-v7a
[1/2] Building CXX object CMakeFiles/LivenessDetectorJni.dir/LivenessDetectorJni.cpp.o
[2/2] Linking CXX shared library /home/jnitest/common-silent/build/intermediates/cmake/debug/obj/armeabi-v7a/libLivenessDetectorJni.so
Build LivenessDetectorJni x86_64
[1/2] Building CXX object CMakeFiles/LivenessDetectorJni.dir/LivenessDetectorJni.cpp.o
[2/2] Linking CXX shared library /home/jnitest/app/build/intermediates/cmake/debug/obj/x86_64/libLivenessDetectorJni.so
Build LivenessDetectorJni x86
[1/2] Building CXX object CMakeFiles/LivenessDetectorJni.dir/LivenessDetectorJni.cpp.o
[2/2] Linking CXX shared library /home/jnitest/app/build/intermediates/cmake/debug/obj/x86/libLivenessDetectorJni.so
Build LivenessDetectorJni arm64-v8a
[1/2] Building CXX object CMakeFiles/LivenessDetectorJni.dir/LivenessDetectorJni.cpp.o
[2/2] Linking CXX shared library /home/jnitest/app/build/intermediates/cmake/debug/obj/arm64-v8a/libLivenessDetectorJni.so
Build LivenessDetectorJni armeabi-v7a
[1/2] Building CXX object CMakeFiles/LivenessDetectorJni.dir/LivenessDetectorJni.cpp.o
[2/2] Linking CXX shared library /home/jnitest/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libLivenessDetectorJni.so

2 个答案:

答案 0 :(得分:1)

abiFilter是'ndk'块的一部分。

using namespace std;
int main(){

    ifstream theFile("key.txt");

    int number;
    string text;

    while(theFile>>number>>text){
        cout<<number<<" and "<<text<<endl;
    }
}

在此处查看详细信息。 https://developer.android.com/studio/projects/gradle-external-native-builds#specify-abi

答案 1 :(得分:0)

因为我在android项目中链接了c ++ 2次,所以该项目构建了2次。