Android Studio项目构建成功,但cmake无法生成本机库

时间:2018-07-29 16:01:16

标签: android android-studio cmake android-gradle native

我一直在与本地库一起构建我的Android Studio项目,到目前为止,它工作得很好。最近,它开始不输出本机库。一切仍然可以成功构建,但是在构建日志中看不到与本机库相关的任何输出,并且由于现在尝试与{{1}一起使用该库时失败,因此无法在设备上运行该应用程序}错误。

我认为此问题可能与以下事实有关:我转而将其构建为STATIC库而不是SHARED库。

我的应用程序级别java.lang.UnsatisfiedLinkError

build.gradle

我的CMakeLists.txt文件

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'c'

android {
    compileSdkVersion 25
    defaultConfig {
        applicationId "com.vrazo"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1529505857
        versionName "2018.6.20"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

        externalNativeBuild {
            cmake {
                cppFlags "-latomic"
                arguments "-DCMAKE_VERBOSE_MAKEFILE=1", "-DANDROID_UNIFIED_HEADERS=ON"
            }
        }

        ndk {
            // Specifies the ABI configurations of your native
            // libraries Gradle should build and package with your APK.
            abiFilters 'armeabi-v7a', 'x86', 'arm64-v8a'// ,x86_64, armeabi
            //, 'mips', 'mips64'
        }

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
}

buildscript {
    //repositories {
    //    maven { url 'https://maven.fabric.io/public' }
    //}

    //dependencies {
        // The Fabric Gradle plugin uses an open ended version to react
        // quickly to Android tooling updates
    //    classpath 'io.fabric.tools:gradle:1.+'
    //}
}

//repositories {
//    maven { url 'https://maven.fabric.io/public' }
//}

//crashlytics {
//    enableNdk true
//    manifestPath 'src/main/AndroidManifest.xml'
//}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation project(':library_ripple_backgroud_effect')
    implementation project(':ccp')



    implementation 'com.github.bumptech.glide:glide:3.7.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.android.volley:volley:1.0.0'
    implementation 'com.android.support:appcompat-v7:25.3.1'
    implementation 'com.android.support:cardview-v7:25.2.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.shawnlin:number-picker:2.4.3'
    implementation 'com.daasuu:EasingInterpolator:1.0.0'
    implementation 'com.android.support:design:25.3.1'
    testImplementation 'junit:junit:4.12'

    //compile('com.crashlytics.sdk.android:crashlytics:2.9.3@aar') {
    //    transitive = true
    //}

    //compile('com.crashlytics.sdk.android:crashlytics-ndk:2.0.4') {
    //    transitive = true
    //}

    //compile('io.fabric.sdk.android:fabric:1.4.2@aar') {
    //    transitive = true
   // }

    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'

    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.9.3'
}

apply plugin: 'com.google.gms.google-services'

1 个答案:

答案 0 :(得分:1)

您不能直接从Java加载静态本机库。您必须链接所有静态库以形成共享(动态)库,并使用Java中的System.loadLibrary()来利用它。