編譯Android Gallery圖庫源碼所遇bug

轉載請註明出處: http://blog.csdn.net/lb377463323/article/details/68936291

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]

將eclipse中
http://schemas.android.com/apk/res/com.xxx.xxx

換成
http://schemas.android.com/apk/res-auto

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.

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