jniLibs.srcDirs不能打包so到apk中?

一般使用AS开发Android应用时,调用ndk的so库,我都喜欢添加abiFilter不想浪费空间嘛!所以,so库目录一般都是XXXPATH/armeabi-v7a/xxxooo.so类似的,今天引用到第三方库,又不想(没必要)拷贝到src/main/jniLibs下,那就配置:

sourceSets {
        main {
            jniLibs.srcDirs = ['paddle-android/lib/${ANDROID_ABI}']
        }
    }

满心欢喜的编译,死活不能打包到apk这就奇了怪了,网上不都是这样的语法么?


幸亏脑袋能转弯,既然是路径问题,好好考虑一下吧!!!


我们是希望将${ANDROID_ABI}的so拷贝打包,会不会是既然AS已经知道了${ANDROID_ABI}我们就只需指定上一层,AS自然会遍历${ANDROID_ABI}得到所想要的依赖库,好,

去掉${ANDROID_ABI},指向上一层:


apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.paddlepaddle.aicamera"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags "-std=c++11 -frtti -fexceptions"
            }
        }
        ndk {
            abiFilter "armeabi-v7a"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }

    sourceSets {
        main {
            jniLibs.srcDirs = ['paddle-android/lib'] //这里就不要再加abiFilter了
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

果然,so库拷贝打包成功!


你可能感兴趣的:(机器学习,android)