1. 程式人生 > >編譯Android Gallery相簿原始碼所遇bug

編譯Android Gallery相簿原始碼所遇bug

1. selectiveAdjust() isnot supported in SDK levels 11-15

Error:(99, 32) error: Non-root compute kernel selectiveAdjust() is not supported in SDK levels 11-15
F:\Apps\GalleryActivity\app\src\main\rs\grad.rs
Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies]

在清單檔案中設定minSdkVersion大於15即可

2. ScriptC_grad cannot be resolved to a type

Description Resource Path Location Type
ScriptC_grad cannot be resolved to a type ImageFilterGrad.java /GalleryActivity/src/com/android/gallery3d/filtershow/filters line 146 Java Problem

這是Eclipse的Android Dependencies找不到renderscript-v8.jar這個包,或者這個包的版本不對。

如果是找不到這個包的話,右鍵專案名 -> 點選Properties ->Java Build Path -> Libraries -> Add External JARs。

如果是包版本不對的話,開啟project.properties檔案,設定sdk.buildtools為正確版本即可,如sdk.buildtools=25.0.2。如果不在此處設定的話會預設使用sdk中Build-Tools的最高版本,你把版本過高的Build-Tools解除安裝掉也行。

3. AndroidStudio找不到RenderScript

在AndroidStudio中使用V8包中的RenderScript,只需要修改專案的build.gradle中的程式碼即可

android {
     ...
     defaultConfig {
          ...
          renderscriptTargetApi 18
          renderscriptSupportModeEnabled true
     }
     ...
}

4. Duplicate files copied in APK META-INF/DEPENDENCIES

Error:Execution failed for task ‘:app:transformResourcesWithMergeJavaResForDebug’.
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/DEPENDENCIES
File1: F:\Apps\GalleryActivity\app\libs\httpclient-4.5.3.jar
File2: F:\Apps\GalleryActivity\app\libs\httpcore-4.4.6.jar

這是因為兩個包裡面有檔案重複了, 開啟專案下面的 build.gradle 檔案,在 android 程式碼塊中新增下面程式碼,排除掉重複檔案

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/MANIFEXT.MF'
}

5. Your project contains C++ files but it is not using a supported native build system

Error:Execution failed for task ‘:app:compileDebugNdk’.
Error: Your project contains C++ files but it is not using a supported native build system.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
https://developer.android.com/studio/build/experimental-plugin.html.

首先在工程目錄下的gradle.properties檔案的末尾加上一句(如果沒有gradle.properties檔案 ,自己拷一份進來):
Android.useDeprecatedNdk=true
然後再在檔案build.gradle(Module:app)裡面的buildTypes類中新增一個這樣的方法

sourceSets {
main {
jni.srcDirs = []
}
}

6. INSTALL_FAILED_CONFLICTING_PROVIDER

Installation failed with message Failed to finalize session : INSTALL_FAILED_CONFLICTING_PROVIDER: Package couldn’t be installed in /data/app/com.android.gallery3d-1: Can’t install because provider name com.android.gallery3d.provider (in package com.android.gallery3d) is already used by com.vivo.gallery.
It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing.

把清單檔案裡面的provider的android:authorities改成別的名字,我這裡是在最後加1

<provider android:name="com.android.gallery3d.provider.GalleryProvider"
        android:syncable="false"
        android:grantUriPermissions="true"
        android:exported="true"
        android:permission="com.android.gallery3d.permission.GALLERY_PROVIDER1"
        android:authorities="com.android.gallery3d.provider1" />

如果出現INSTALL_FAILED_DUPLICATE_PERMISSION這個錯誤,就把清單檔案的自定義permission的name改掉

<permission android:name="com.android.gallery3d.permission.GALLERY_PROVIDER1"
        android:protectionLevel="signatureOrSystem" />

<uses-permission android:name="com.android.gallery3d.permission.GALLERY_PROVIDER1" />

還有一種情況:手機一解除安裝衝突的那個APP,但是還是提示此錯誤,這可能是解除安裝不乾淨。
在終端中使用adb解除安裝即可: adb uninstall 包名

7. http:// schemas.android.com/apk/res-auto

Error:(19) Error: In Gradle projects, always use http://schemas.android.com/apk/res-auto for custom attributes [ResAuto]

8,Gradle DSL method not found: ‘android()’

Error:(16, 0) Gradle DSL method not found: ‘android()’
Possible causes:

刪除專案根目錄build.gradle裡面的android標籤,如下圖整個框內都刪除,然後重新編譯

9, NDK integration is deprecated in the current plugin

Error:(14, 0) Error: NDK integration is deprecated in the current plugin. Consider trying the new experimental plugin. For details, see http://tools.android.com/tech-docs/new-build-system/gradle-experimental. Set “android.useDeprecatedNdk=true” in gradle.properties to continue using the current NDK integration.
Open File

在gradle.properties檔案中新增android.useDeprecatedNdk=true

注意大小寫不可錯

10,找不到符號

如果出現類似以下的錯誤:

Error:(95, 45) 錯誤: 找不到符號 符號: 變數 FORMAT_DNG 位置: 類 MtpConstants

檢查build.tools版本,很大可能是因為build.tools版本太低了

11, java.lang.ClassNotFoundException,Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

如果遇到Android Studio直接run可以執行APP,但是Build APK生成的不能執行,出現上述報錯資訊,很大可能是因為Instant Run導致的,把它禁掉再重新生成apk就行了。

Android Studio –> File –> Setting –> Build, execution, deploy –> Instant Run.