Ich bin froh, dass Sie es herausgefunden haben. Ich werde die Antwort hier trotzdem als Referenz veröffentlichen.
CMakeLists.txt < < = sollte root dir in der App-Modul (my_project/app/CMakeLists.txt
)
# https://developer.android.com/studio/projects/add-native-code.html#create-cmake-script
# Minimum version of CMake
cmake_minimum_required(VERSION 3.4.1)
# adding CEC library
# add_library structure: add_library(lib_name lib_type_STATIC_or_SHARED source_file_path)
add_library(my_lib_name SHARED src/main/jni/my_cpp_file.cpp)
# include_directories is to provide the path to you native lib code
# include_directories structure: include_directories(native_lib_folder_path)
include_directories(src/main/jni/)
# adding Android log library
# find_library is used to find NDK API libraries (built in NDK libs)
# find_library structure: find_library(name_you_want_to_call_the_lib lib_name_in_ndk_api)
find_library(log-lib log)
# linking log lib to our native lib
# once you find the library, you have to link that library with your native library
# target_link_libraries structure: target_link_libraries(you_native_lib lib_found_using_find_library)
target_link_libraries(my_lib_name ${log-lib})
Dann in build.gradle, gehen Sie wie folgt
externalNativeBuild {
cmake {
path 'CMakeLists.txt'
}
}
Dann führen Sie eine vollständige sauber, Aktualisieren Sie das C++ - Projekt mithilfe der Option im Menü Erstellen.
Und wie @bitwise gebucht, wenn Sie müssen, löschen Sie den Inhalt von build
und .externalNativeBuild
Ordner und erstellen Sie das Projekt neu.
Was stimmt nicht mit dem Namen der Ausgabedatei? –
Überprüfen Sie die Android.mk-Dateien in Ihrem Projekt. – Moved
Wenn Sie die neuen Android Studio C++ Support-Funktionen verwenden, zeigen Sie uns die 'build.gradle' oder, wenn Sie' CMake' verwenden, die 'CMakeLists.txt' Datei. Stellen Sie außerdem sicher, dass Sie nach dem Ändern des Namens den Code im Code ändern, wenn Sie die Bibliothek laden: 'System.loadLibrary (" myname.so ")' –