首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android Studio项目构建成功,但cmake未生成本机库

Android Studio项目构建成功,但cmake未生成本机库
EN

Stack Overflow用户
提问于 2018-07-30 00:01:16
回答 1查看 512关注 0票数 0

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

我认为这个问题可能与我转而将其构建为静态库而不是共享库有关。

我的应用层build.gradle

代码语言:javascript
复制
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文件

代码语言:javascript
复制
# 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 )
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-31 08:04:12

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51582117

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档