2017-12-07 7 views
2

hello-libs Google 예제 코드를 빌드 할 수 있으며 사전 빌드 라이브러리가 대상 apk에 올바르게 복사되었습니다.android-ndk 미리 빌드 라이브러리를 apk에 복사하지 않습니다.

하지만 내 응용 프로그램에서는 컴파일이 끝났지 만 apk에는 사전 빌드 라이브러리가 포함되어 있지 않습니다.

두 가지 문제 :

  1. 빌드 출력 APK lib 디렉토리는 arm64 버전이 포함되어 있습니다,하지만 난 build.gradle에 armeabi, armeabi-V7A 및 arm64을 정의했습니다. 왜 그것이 효과가 없는지 확신하지 못한다.

lib/ └── arm64-v8a └── libFFmpegWrapper.so

사전 빌드 라이브러리가 모든 APK lib 디렉토리에 포함,하지만 난 내 build.gradle에서 jniLibs 라인이되지
  • , 내가 확인 지옥 libs와
      을 , 그것은 같은 것처럼 보입니다. 아래

    상세 정보 :

    안드로이드 스튜디오 버전 : 3.0.1 OS가 :

    ├── app 
    │   ├── libs 
    │   └── src 
    │    ├── main 
    │    │   ├── cpp 
    │    │   │   └── ffmpeg 
    │    │   │    ├── arm64-v8a 
    │    │   │    │   ├── bin 
    │    │   │    │   ├── include 
    │    │   │    │   ├── lib 
    │    │   │    ├── armeabi 
    │    │   │    │   ├── include 
    │    │   │    │   ├── lib 
    │    │   │    └── armeabi-v7a 
    │    │   │     ├── include 
    │    │   │     ├── lib 
    │    │   ├── java 
    │    │   │   └── com 
    │    │   │    └── example 
    │    │   │     └── ffmpegtest 
    │    │   │      └── recorder 
    

    build.gradle : 아래 10.13.1

    내 파일 디렉토리 구조를에서라도

    apply plugin: 'com.android.application' 
    
    android { 
        compileSdkVersion 26 
        defaultConfig { 
         applicationId "com.example.ffmpegtest" 
         minSdkVersion 23 
         targetSdkVersion 26 
         versionCode 1 
         versionName "1.0" 
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
         ndk { 
          abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a' 
         } 
         externalNativeBuild { 
          cmake { 
           cmake { 
            arguments '-DANDROID_PLATFORM=android-26', 
              '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=gnustl_static' 
           } 
          } 
         } 
        } 
        buildTypes { 
         release { 
          minifyEnabled false 
          proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
         } 
        } 
        sourceSets { 
         main { 
          // let gradle pack the shared library into apk 
          jniLibs.srcDirs = ['src/main/cpp/ffmpeg'] 
         } 
        } 
        externalNativeBuild { 
         cmake { 
          path "CMakeLists.txt" 
         } 
        } 
    } 
    
    dependencies { 
        implementation fileTree(dir: 'libs', include: ['*.jar']) 
        implementation 'com.android.support:appcompat-v7:26.1.0' 
        implementation 'com.android.support.constraint:constraint-layout:1.0.2' 
        testImplementation 'junit:junit:4.12' 
        androidTestImplementation 'com.android.support.test:runner:1.0.1' 
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 
    } 
    

    CMakeList.txt

    cmake_minimum_required(VERSION 3.4.1) 
    
    set(FFMPEG_DIR ${CMAKE_SOURCE_DIR}/src/main/cpp/ffmpeg) 
    
    add_library(avutil-55 SHARED IMPORTED) 
    set_target_properties(avutil-55 
        PROPERTIES IMPORTED_LOCATION 
        ${FFMPEG_DIR}/${ANDROID_ABI}/lib/libavutil-55.so) 
    
    add_library(avformat-57 SHARED IMPORTED) 
    set_target_properties(avformat-57 
        PROPERTIES IMPORTED_LOCATION 
        ${FFMPEG_DIR}/${ANDROID_ABI}/lib/libavformat-57.so) 
    
    add_library(avcodec-57 SHARED IMPORTED) 
    set_target_properties(avcodec-57 
        PROPERTIES IMPORTED_LOCATION 
        ${FFMPEG_DIR}/${ANDROID_ABI}/lib/libavcodec-57.so) 
    
    add_library(avfilter-6 SHARED IMPORTED) 
    set_target_properties(avfilter-6 
        PROPERTIES IMPORTED_LOCATION 
        ${FFMPEG_DIR}/${ANDROID_ABI}/lib/libavfilter-6.so) 
    
    add_library(swresample-2 SHARED IMPORTED) 
    set_target_properties(swresample-2 
        PROPERTIES IMPORTED_LOCATION 
        ${FFMPEG_DIR}/${ANDROID_ABI}/lib/libswresample-2.so) 
    
    add_library(swscale-4 SHARED IMPORTED) 
    set_target_properties(swscale-4 
        PROPERTIES IMPORTED_LOCATION 
        ${FFMPEG_DIR}/${ANDROID_ABI}/lib/libswscale-4.so) 
    
    set(FFMPEG_LIBS 
        avutil-55 
        avformat-57 
        avcodec-57 
        avfilter-6 
        swresample-2 
        swscale-4) 
    
    include_directories(${FFMPEG_DIR}/${ANDROID_ABI}/include) 
    
    set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=softfp -mfpu=neon -g -O0") 
    
    add_library(# Sets the name of the library. 
          FFmpegWrapper 
    
          # Sets the library as a shared library. 
          SHARED 
    
          # Provides a relative path to your source file(s). 
          src/main/cpp/FFmpegWrapper.c 
          ) 
    
    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 
          ) 
    
    target_link_libraries(# Specifies the target library. 
    
             FFmpegWrapper 
    
             # Links the target library to the log library 
             # included in the NDK. 
             ${log-lib} 
    
             # ffmpeg library 
             ${FFMPEG_LIBS} 
             ) 
    
  • 답변

    2

    공유 라이브러리 디렉토리 구조는 다음과 같이 변경해야합니다 :

    src/main/cpp/ 
    └── ffmpeg 
        ├── include 
        └── lib 
         ├── arm64-v8a 
         ├── armeabi 
         └── armeabi-v7a 
    

    그리고 올바른 위치에 다른 코드 라인을 변경합니다.

    cmake_minimum_required(VERSION 3.4.1) 
    
    set(FFMPEG_DIR ${CMAKE_SOURCE_DIR}/src/main/cpp/ffmpeg) 
    
    # library directory structure 
    # src/main/cpp/ 
    # └── ffmpeg 
    #  ├── include 
    #  └── lib 
    #   ├── arm64-v8a 
    #   ├── armeabi 
    #   └── armeabi-v7a 
    include_directories(${FFMPEG_DIR}/include) 
    set(FFMPEG_LIBS 
        avutil-55 
        avformat-57 
        avcodec-57 
        avfilter-6 
        swresample-2 
        swscale-4) 
    
    foreach(libname ${FFMPEG_LIBS}) 
        message(add lib ${libname}) 
        add_library(${libname} SHARED IMPORTED) 
        set_target_properties(${libname} PROPERTIES IMPORTED_LOCATION 
         ${FFMPEG_DIR}/lib/${ANDROID_ABI}/lib${libname}.so) 
    endforeach() 
    
    set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=softfp -mfpu=neon -g -O0") 
    add_library(FFmpegWrapper SHARED src/main/cpp/FFmpegWrapper.c) 
    find_library(log-lib log) 
    target_link_libraries(FFmpegWrapper ${log-lib} ${FFMPEG_LIBS}) 
    

    build.gradle :

    apply plugin: 'com.android.application' 
    
    android { 
        compileSdkVersion 26 
        defaultConfig { 
         ... 
         ndk { 
          abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a' 
         } 
         ... 
        } 
        ... 
        sourceSets { 
         main { 
          // let gradle pack the shared library into apk 
          jniLibs.srcDirs = ['src/main/cpp/ffmpeg/lib'] 
         } 
        } 
        externalNativeBuild { 
         cmake { 
          path "CMakeLists.txt" 
         } 
        } 
    } 
    
    dependencies { 
        ... 
    } 
    
    CMakeList.txt 아마 다음과 같다