我正在構建一個應用程序,我正在使用舊版的HTC Desire S來調試和測試應用程序。在這款手機上運行的Android 2.3.5版本,我的應用程序的最低SDK設置爲10.Android:Glide/SDK/gradle錯誤
此外,由於這些令人敬畏的規格,我的手機在導入JPEG時,作爲位圖ImageView(可能由於JPEG的大小),並在處理某些文件時崩潰。
public void showImage() {
String filePath = contentDirectory + "/" + filesInFolder[image_index];
ImageView imgView = (ImageView) findViewById(R.id.myimage);
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
ImageView imgView = (ImageView) findViewById(R.id.myimage);
imgView.setImageBitmap(bitmap);
}
經過一番搜索後,我發現我應該使用Glide來解決我的問題。
繼滑翔Github的頁面上的說明,我插入的build.gradle如下:
dependencies {
compile 'com.github.bumptech.glide:glide:4.0.0-RC1'
compile 'com.android.support:support-v4:25.3.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0-RC1'
}
和dislplay圖像爲:
public void showImage() {
String filePath = contentDirectory + "/" + filesInFolder[image_index];
ImageView imgView = (ImageView) findViewById(R.id.myimage);
Glide.with(this).load(filePath).into(imgView);
}
當運行我的應用程序,它崩潰。我因此將compile 'com.android.support:support-v4:25.3.1'
更改爲compile 'com.android.support:support-v4:10.3.1'
(版本25到10)。
我現在得到的錯誤
This support library should not use a different version (10) than the compileSdkVersion (25)
,我因此設置compileSdkVersion 10:
android {
compileSdkVersion 10
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.XXX.myapplication"
minSdkVersion 10
targetSdkVersion 10
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
}
同步的gradle這個文件後,我收到了一大堆錯誤的,個個都位於在
C:...\MyApplication\app\build\intermediates\res\merged\debug\
如果有必要我可以發佈他們所有(有很多),但我認爲主要我這裏ssue是我的錯誤:
Cannot resolve symbol 'R'
是否有任何人誰可以提供解決方案或點我在正確的方向?
再次感謝!
編輯: 故障轉儲在行:
Glide.with(this).load(filePath).into(imgView);
01-06 04:05:13.929 21324-21324/com.example.XXX.myapplication I/dalvikvm: Failed resolving Lcom/bumptech/glide/Glide; interface 59 'Landroid/content/ComponentCallbacks2;'
01-06 04:05:13.929 21324-21324/com.example.XXX.myapplication W/dalvikvm: Link of class 'Lcom/bumptech/glide/Glide;' failed
01-06 04:05:13.929 21324-21324/com.example.XXX.myapplication I/dalvikvm: Could not find method com.bumptech.glide.Glide.with, referenced from method com.imageviewexample.ImageViewExample.showImage
01-06 04:05:13.929 21324-21324/com.example.XXX.myapplication W/dalvikvm: VFY: unable to resolve static method 17289: Lcom/bumptech/glide/Glide;.with (Landroid/app/Activity;)Lcom/bumptech/glide/RequestManager;
01-06 04:05:13.929 21324-21324/com.example.XXX.myapplication D/dalvikvm: VFY: replacing opcode 0x71 at 0x0028
01-06 04:05:13.929 21324-21324/com.example.XXX.myapplication D/dalvikvm: VFY: dead code 0x002b-0033 in Lcom/imageviewexample/ImageViewExample;.showImage()V
01-06 04:05:13.959 21324-21324/com.example.XXX.myapplication D/AndroidRuntime: Shutting down VM
01-06 04:05:13.959 21324-21324/com.example.XXX.myapplication W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x4001d5a0)
01-06 04:05:13.969 21324-21324/com.example.XXX.myapplication E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.bumptech.glide.Glide
at com.imageviewexample.ImageViewExample.showImage(ImageViewExample.java:78)
at com.imageviewexample.ImageViewExample.onCreate(ImageViewExample.java:53)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1836)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1893)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4385)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)
那麼爲什麼你從25版改爲10呢? – tyczj
,因爲我認爲我的應用程序在啓動時崩潰,因爲它無法處理版本25,因爲它在android 2.3.5上運行 – daan166
刪除**/app/build **文件夾,並嘗試重新生成項目並看看它是否工作順便說一句爲什麼你改變支持lib版本它完全不相關我就我所知,發佈你的崩潰日誌可能是我們可以解決它們。 –