使用Glide

时间:2018-11-07 02:59:06

标签: java android

我正在尝试在我的应用上使用GlideGlide需要我创建一个扩展Application的类,然后在其中创建一个扩展AppGlideModule的方法。然后,我需要做一个Make Project。由于某种原因,Glide创建了Application类的多个实例,从而导致错误。

我所做的是多次重命名Application类,将类移到另一个文件夹中,但错误仍然相同。将Application类移动到另一个文件夹后,Android Studio检测到该类的2个实例。文件夹外部有1个实例,文件夹内部有1个实例。请注意,Application类已经在文件夹中,并且没有其他类与该类具有相同的名称。

这是我的Application班。

import android.app.Application;

import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;

public class Globals extends Application {

    @GlideModule
    public final class mAppGlideModule extends AppGlideModule {

    }
}

这是我的build.gradle(app)。

android {
    compileSdkVersion 27
    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'

    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.github.bumptech.glide:glide:4.8.0'
}

这是不断出现的错误。

error: class Globals clashes with package of same name

1 个答案:

答案 0 :(得分:0)

将此行添加到gradle中

annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'

并尝试将类名从Globals更改为Application,并将类名添加到清单文件的application标记中

<application
        android:name=".Application"
        android:allowBackup="true"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        tools:ignore="GoogleAppIndexingWarning">
相关问题