NDK 報錯 java.lang.UnsatisfiedLinkError 的一種處理方案 ( 主應(yīng)用與依賴庫 Module 的 CPU 架構(gòu)配置不匹配導(dǎo)致 )(二)
三、解決方案
解決方案 : 全部配置 armeabi-v7a 架構(gòu) , 這樣在所有的手機(jī)中只存在 armeabi-v7a 架構(gòu) 的動態(tài)庫 , 系統(tǒng)查找時 , 就不會查找
android / defaultConfig / externalNativeBuild / cmake / abiFilters 配置 abiFilters 'armeabi-v7a' 即可 ; plugins { id 'com.android.application' id 'kotlin-android' } android { compileSdkVersion 29 buildToolsVersion "30.0.2" defaultConfig { applicationId "kim.hsl.myapplication" minSdkVersion 18 targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { cppFlags "" abiFilters 'armeabi-v7a' } } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } externalNativeBuild { cmake { path "src/main/cpp/CMakeLists.txt" version "3.10.2" } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' }
主應(yīng)用中生成的 動態(tài)庫 , 只剩成了 armeabi-v7a 架構(gòu)的動態(tài)庫 ;
依賴庫中還是生成的 armeabi-v7a 架構(gòu)的動態(tài)庫 ;
問題解決 ;
如果非要配置 arm64-v8a 架構(gòu) , 但是一旦配置上 , 所有的在 NDK 中使用到的依賴庫 如 OpenSSL , FFMPEG , RTMP , FAAC , OpenCV 等 , 都必須一式兩份 , 一份 armeabi-v7a 架構(gòu)的靜態(tài)/動態(tài) 依賴庫 , 一份 arm64-v8a 架構(gòu)的 靜態(tài) / 動態(tài) 依賴庫 ; ( 很麻煩 , APK 編譯后也很大 , 不推薦 )
三、解決計劃
解決計劃 : 悉數(shù)裝備 armeabi-v7a 架構(gòu) , 這樣在一切的手機(jī)中只存在 armeabi-v7a 架構(gòu) 的動態(tài)庫 , 體系查找時 , 就不會查找
android / defaultConfig / externalNativeBuild / cmake / abiFilters 裝備 abiFilters 'armeabi-v7a' 即可 ; plugins { id 'com.android.application' id 'kotlin-android' } android { compileSdkVersion 29 buildToolsVersion "30.0.2" defaultConfig { applicationId "kim.hsl.myapplication" minSdkVersion 18 targetSdkVersion 29 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { cppFlags "" abiFilters 'armeabi-v7a' } } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } externalNativeBuild { cmake { path "src/main/cpp/CMakeLists.txt" version "3.10.2" } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'com.google.android.material:material:1.2.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' testImplementation 'junit:junit:4.+' androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' }
主使用中生成的 動態(tài)庫 , 只剩成了 armeabi-v7a 架構(gòu)的動態(tài)庫 ;
依靠庫中還是生成的 armeabi-v7a 架構(gòu)的動態(tài)庫 ;
問題解決 ;
如果非要裝備 arm64-v8a 架構(gòu) , 可是一旦裝備上 , 一切的在 NDK 中使用到的依靠庫 如 OpenSSL , FFMPEG , RTMP , FAAC , OpenCV 等 , 都必須一式兩份 , 一份 armeabi-v7a 架構(gòu)的靜態(tài)/動態(tài) 依靠庫 , 一份 arm64-v8a 架構(gòu)的 靜態(tài) / 動態(tài) 依靠庫 ; ( 很麻煩 , APK 編譯后也很大 , 不推薦 )