简体   繁体   English

支持库和compileSdkVersion版本不匹配

[英]Support library and compileSdkVersion version mismatch

I am buidling an application and I am using my old HTC Desire S to debug and test the application. 我正在构建应用程序,并且正在使用旧的HTC Desire S调试和测试该应用程序。 On this phone runs Android version 2.3.5, and the minimum SDK of my application is set on 10. 这部手机运行的是Android 2.3.5版,我的应用程序的最低SDK设置为10。

Also, because of these awesome specs, my phone has trouble when importing JPEGs, as a bitmap, in ImageView (probably because of the size of the JPEGs), and crashes when handling certain files. 另外,由于这些出色的规格,我的手机在ImageView中将JPEG作为位图导入JPEG时遇到了麻烦(可能是由于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);
        }

After some searching around I figured that I should use Glide to fix my issues. 经过一番搜索后,我发现我应该使用Glide解决问题。

Following the instructions on the Glide GitHub page, I insert the following in build.gradle: 按照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'
}

And dislplay the image as: 并将图像显示为:

public void showImage() {
        String filePath = contentDirectory + "/" + filesInFolder[image_index];
        ImageView imgView = (ImageView) findViewById(R.id.myimage);
        Glide.with(this).load(filePath).into(imgView);
}

When running my application, it crashes. 运行我的应用程序时,它崩溃。 I therefore changed compile 'com.android.support:support-v4:25.3.1' into compile 'com.android.support:support-v4:10.3.1' (version 25 into 10). 因此,我将compile 'com.android.support:support-v4:25.3.1'更改为compile 'com.android.support:support-v4:10.3.1' (版本25至10)。

I now get the error 我现在得到了错误

This support library should not use a different version (10) than the compileSdkVersion (25) 该支持库不应使用与compileSdkVersion(25)不同的版本(10)。

And I therefore set compileSdkVersion to 10: 因此,我将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
        }
    }
}

After syncing the gradle file, I get a whole lot of errors, all of them are located within 同步gradle文件后,出现很多错误,所有错误都位于

C:...\\MyApplication\\app\\build\\intermediates\\res\\merged\\debug\\ C:\\ MyApplication的\\程序\\建立\\中间体\\水库\\合并\\调试\\

If necessary I can post them all (there are many), but I think that the main issue here is that I get the error: 如有必要,我可以将它们全部张贴(有很多),但是我认为这里的主要问题是我得到了错误:

Cannot resolve symbol 'R' 无法解析符号“ R”

Is there anyone who can provide a solution or point me in the right direction? 有谁能提供解决方案或为我指明正确的方向?

Crashdump at line: 行的故障转储:

Glide.with(this).load(filePath).into(imgView); Glide.with(本).load(文件路径).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)

The reason for me using Glide in the first place was a memory issue with bitmaps and ImageView. 首先使用Glide的原因是位图和ImageView的内存问题。 Unfortunately I and the helpful members above, were not able to solve the issue regarding the Glide crash as described above. 不幸的是,我和上面的帮助成员无法解决如上所述的有关Glide崩溃的问题。

Rather than that I went back to my first problem, which was the memory issue, and solved that by including bitmap.recycle() within my code the moment a new bitmap was displayed. 与其说是第一个问题,不如说是内存问题, bitmap.recycle()通过在显示新位图时在代码中包含bitmap.recycle()来解决该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM