Android Studio项目构建成功,但是cmake没有生成原生库

Android Studio project building successfully, but cmake not generating native library

我一直在构建我的 Android Studio 项目,旁边有一个本机库,到目前为止它运行良好。最近开始不输出原生库了。一切仍然成功构建,但是我在构建日志中看不到任何与本机库相关的输出,并且我无法 运行 设备上的应用程序,因为它现在尝试使用库时失败java.lang.UnsatisfiedLinkError 错误。

我认为这个问题可能与我转而将其构建为 STATIC 库而不是 SHARED 库有关。

我的应用级别build.gradle

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'

我的CMakeLists.txt文件

# Sets the minimum version of CMake required to build the native
# library. You should either keep the default value or only pass a
# value of 3.4.0 or lower.

cmake_minimum_required(VERSION 3.4.1)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/out/)

add_library ( vtr-lib STATIC
    src/main/cpp/vtr/vtr_w.c
    src/main/cpp/vtr/vtrstate_controller_w.c
    src/main/cpp/vtr/util/vtrutil.c

    # The API Wrapper Files
    src/main/cpp/vtr/vtrapi_w.c
    src/main/cpp/vtr/util/vtrutil.c
)

# Import the log library
find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

# Import the ZLIB Library
find_library( # Sets the name of the path variable.
              zlib-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              z )

# Add the SSL Include Directories based on the current architecture
include_directories (
    src/main/cpp/libs/${ANDROID_ABI}/include/
    src/main/cpp/libs/${ANDROID_ABI}/include/state_machine/
    src/main/cpp/vtr/
    src/main/cpp/vtr/util/
)

# Add the SSL Library based on the current architecture
add_library ( ssl-lib STATIC IMPORTED )
set_target_properties ( ssl-lib PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/cpp/libs/${ANDROID_ABI}/libssl.a )

# Add the Crypto Library based on the current architecture
add_library ( crypto-lib STATIC IMPORTED )
set_target_properties ( crypto-lib PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/cpp/    libs/${ANDROID_ABI}/libcrypto.a )

# Add core vvp library
add_library ( vvp-lib STATIC IMPORTED )
set_target_properties( vvp-lib PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/cpp/libs/${ANDROID_ABI}/libvvp.a )

# Add the state machine library
add_library( statemachine-lib STATIC IMPORTED )
set_target_properties( statemachine-lib PROPERTIES IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/src/main/cpp/    libs/${ANDROID_ABI}/libvtrstatemachine.a )

# Link the libraries to the native library
target_link_libraries ( vtr-lib ssl-lib crypto-lib statemachine-lib atomic ${log-lib} ${zlib-lib} vvp-lib )

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