java - 使用 Glide 时类与同名包冲突
问题描述
我正在尝试Glide
在我的应用程序上使用。Glide
需要我创建一个扩展的类,Application
然后在里面我需要创建一个扩展的方法AppGlideModule
。然后我需要做一个Make Project
我做过的事情。出于某种原因,创建了导致错误Glide
的类的多个实例。Application
我所做的是Application
多次重命名类,将类移到不同的文件夹中,但错误仍然相同。将Application
类移动到不同的文件夹后,Android Studio
检测到该类的 2 个实例。一个在文件夹外的实例和另一个在文件夹内的实例。请注意,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
解决方案
在 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">
推荐阅读
- gradle - Quarkus - 多模块项目中的全局 application.properties
- google-cloud-platform - 如何从应用程序默认凭据生成的凭据中模拟 GCP 服务帐户
- c# - 仅在没有 null 或零时才设置值,否则抛出异常
- javascript - 我有一个简单的网站,想在鼠标悬停时更改字体大小,但这段代码不起作用。为什么?
- xamarin - Xamarin Forms 标签跨入口边界
- python - 将值从结构存储到文件
- css - 如何找出应该使用什么类/选择器来设置元素的样式?
- selenium-webdriver - cucumber-selenium-testng 框架需要什么依赖项
- rest - 是否有 API 调用可用于检查 Here API 的运行状况?
- c# - 在 Unity 3D 中将多个游戏对象捕捉到另一个