JNI開發篇——報錯:Flag android.useDeprecatedNdk is no longer supported and will be removed in the next……


大概意思就是說:

  1. android.useDeprecatedNdk不再支持了
  2. 讓使用CMake or ndk-build
  3. 然后還有鏈接

解決方法:

1、先通過SDKManager下載:CMake和LLDB

2、在build.gradle的defaultConfig節點下加入:

// 使用Cmake工具
    externalNativeBuild {
      cmake {
        cppFlags ""
        //生成多個版本的so文件
        abiFilters 'arm64-v8a','armeabi-v7a','x86','x86_64'
      }
    }

在build.gradle的android節點下加入:

// 配置CMakeLists.txt路徑
  externalNativeBuild {
    cmake {
      path "CMakeLists.txt"  // 設置所要編寫的c源碼位置,以及編譯后so文件的名字
    }
  }

3、添加CMakeLists.txt文件到build.gradle文件同級目錄下,具體內容如下:

 

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.
#CMakeLists.txt
cmake_minimum_required(VERSION 3.4.1)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
      # 設置so文件名稱.
       NameProvider

       # Sets the library as a shared library.
       SHARED
       # 設置這個so文件為共享.

       # Provides a relative path to your source file(s).
       # 設置這個so文件為共享.
       src/main/jni/getName.cpp)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

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 )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
            # 制定目標庫.
            NameProvider

            # Links the target library to the log library
            # included in the NDK.
            ${log-lib} )

至此,我們所有的流程都做完了,下面來檢查一下我們的成果,見證奇跡的時候到了:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM