Android 開發常用問題彙總-1

1.flavors 造成的錯誤
Android 3.0之後的配置方式

Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html

錯誤原因:在於我們添加了productFlavors。 當flavors 超過一個之後,我們需要在defaultConfig 告訴Gradle 使用默認的,否則腳本找不到flavors 無法進行編譯。
解決方法:

defaultConfig {
        flavorDimensions "default"
    }

2.android:shareUserId造成的錯誤

Installation failed with message INSTALL_FAILED_SHARED_USER_INCOMPATIBLE: Package couldn't be installed in /data/app/com.xxx.xxxx-1: Package com.xxx.xxxx has no signatures that match those in shared user android.uid.system; ignoring!.
It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing.



在這裏插入圖片描述
主要原因在於AndroidManifest.xml 文件中添加了 android:sharedUserId=“android.uid.system”
表示當前應用和系統應用採用同一命名空間。 但是簽名卻和系統應用簽名不一致造成的錯誤。
解決方法有兩種:
1.使用相同簽名進行打包。
2.刪除掉sharedUserId吧。

Installation did not succeed.
The application could not be installed: INSTALL_FAILED_SHARED_USER_INCOMPATIBLE
Installation failed due to: 'null'

能夠進行生成apk,但是無法安裝到設備中,這個錯誤主要原因也同樣在於shareUserId。
簽名和shareUserId 不匹配造成的。

有時候我們確定自己的簽名是正確的,但是還是會提示INSTALL_FAILED_SHARED_USER_INCOMPATIBLE
那可能是你的Build Variants 默認設置的Debug版本,而你的Debug版本的簽名可能默認使用系統Debug 簽名,這種情況下也會出現 提示簽名不正確的問題。

解決方法:

 buildTypes {
        release {
            minifyEnabled true
            zipAlignEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            zipAlignEnabled false
            signingConfig null    // 這個是關鍵
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

在buildTypes 之中 的debug 類型裏面, 輸入singingConfig null 。這個的意思就是取消系統默認的debug 的簽名,然後程序會自動根據你的productFlavors之中定義的簽名進行打包了。

3.NDK不匹配造成的錯誤

RROR:  Parse error.  Expected a command name, got unquoted argument with text " } ". 
Open File

ERROR:  CMakeSystemSpecificInitialize.cmake 
Open File

ERROR: /xxxx/AndroidSDK/xxx/app/.externalNativeBuild/cmake/release/armeabi-v7a/CMakeFiles/3.6.0-rc2/CMakeCCompiler.cmake 
Open File

SIMPLE: CMake Error: Error in cmake code at

SIMPLE: Parse error.  Expected a command name, got unquoted argument with text " }".

SIMPLE: CMake Error: Could not find cmake module file: CMakeSystemSpecificInformation.cmake

SIMPLE: CMake Error in CMakeLists.txt:

SIMPLE:   No CMAKE_C_COMPILER could be found.

SIMPLE:   Tell CMake where to find the compiler by setting the CMake cache entry

SIMPLE:   CMAKE_C_COMPILER to the full path to the compiler, or to the compiler name

SIMPLE:   if it is in the PATH.

ERROR:    No CMAKE_CXX_COMPILER could be found. 
Open File

SIMPLE:   CMAKE_CXX_COMPILER to the full path to the compiler, or to the compiler

SIMPLE:   name if it is in the PATH.

ERROR:  CMAKE_CXX_COMPILER not set, after EnableLanguage 
Open File

出現錯誤的主要原因不在於你的NDK下載錯誤,而在於你下載安裝的cmake 不匹配你下載的NDK造成的錯誤。例如NDK版本要遠遠高於你的cmake版本。

解決方法:
重新更新你的Cmake版本, 如果是ndk 16之前以及20.0可以使用cmake 3.6版本,如果是21.0 請使用3.10版本。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章