Glide Library java.lang.NoClassDefFoundError

时间:2018-01-01 09:14:46

标签: android gradle kotlin android-glide

我正在使用Glide Library来加载可绘制资源文件中的图像,但是我遇到了NoClassDefFoundError。我已经在堆栈中尝试了很多方法,但是我没有解决问题。我实现的活动是Fragment.Here是守则......

class F12 : Fragment() {
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {

     val myImageViewLayout : View = inflater!!.inflate(R.layout.f12, container, false)
      val imageView = myImageViewLayout.findViewById<ImageView>(R.id.preview12)

    Glide
            .with(context)
            .load(R.drawable.a12)
            .into(imageView)

    return myImageViewLayout

}
 override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
    val shareButton =view!!.findViewById<Button>(R.id.b12)
    val wallButton = view.findViewById<Button>(R.id.wb12)
    val adRequest = AdRequest.Builder().build()

    shareButton.setOnClickListener {

        val shareIntent = Intent()
        shareIntent.action = Intent.ACTION_SEND
        shareIntent.putExtra(Intent.EXTRA_TEXT, "ከመሸ ፍቅራችን ደራ…ወደኋላ አንመልሰዉ ነገር ሆነብን….ቀልዳችን የምር ሲሆን፣ቅዠት ያልነዉ  እዉን ሲሆን ሲጨላልም አየነዉ")
        shareIntent.type = "text/plain"
        startActivity(Intent.createChooser(shareIntent, "ሼር ያድርጉ..."))
  }
   }

这里是gradle.app模块..

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android 
  {
compileSdkVersion 26
buildToolsVersion "26.0.3"
defaultConfig {
   applicationId "com.afc.amhariclovequotes"
   minSdkVersion 14
   targetSdkVersion 26
   versionCode 1
   versionName "1.0"
   multiDexEnabled true
 }
buildTypes {
    release {
        minifyEnabled true
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
 dexOptions {      
    javaMaxHeapSize "4g"
}
 }
 dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile 'com.android.support:appcompat-v7:26.0.0'
compile 'com.android.support:mediarouter-v7:26.0.0'
compile 'com.android.support:design:26.0.0'
compile 'com.google.firebase:firebase-ads:11.6.0'
compile 'com.google.firebase:firebase-crash:11.6.0'
compile 'com.google.firebase:firebase-core:11.6.0'
compile 'com.google.firebase:firebase-messaging:11.6.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
compile 'com.github.bumptech.glide:glide:4.4.0@aar'
kapt 'com.github.bumptech.glide:compiler:4.4.0'
testCompile 'junit:junit:4.12'    
 }
 repositories {
 mavenCentral()
 }
 apply plugin: 'com.google.gms.google-services'

以下是关于代码的Android Monitor Complains ...

FATAL EXCEPTION: main
Process: com.afc_quotes.first_amharic_love_quotes, PID: 24273
java.lang.NoClassDefFoundError: com.bumptech.glide.load.resource.gif.GifBitmapProvider
at com.bumptech.glide.load.resource.gif.ByteBufferGifDecoder.<init>(ByteBufferGifDecoder.java:68)
at com.bumptech.glide.load.resource.gif.ByteBufferGifDecoder.<init>(ByteBufferGifDecoder.java:54)
at com.bumptech.glide.Glide.<init>(Glide.java:327)
at com.bumptech.glide.GlideBuilder.build(GlideBuilder.java:445)
at com.bumptech.glide.Glide.initializeGlide(Glide.java:257)
at com.bumptech.glide.Glide.initializeGlide(Glide.java:212)
at com.bumptech.glide.Glide.checkAndInitializeGlide(Glide.java:176)
at com.bumptech.glide.Glide.get(Glide.java:160)
at com.bumptech.glide.Glide.getRetriever(Glide.java:612)
at com.bumptech.glide.Glide.with(Glide.java:638)
**at com.afc.amhariclovequotes.F12.onCreateView(F12.kt:50)**
at android.support.v4.app.Fragment.performCreateView(Fragment.java:2337)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1740)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1809)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2580)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2367)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2322)
at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2199)
at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:651)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:145)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1236)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1084)
at android.support.v4.view.ViewPager$3.run(ViewPager.java:267)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:603)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

3 个答案:

答案 0 :(得分:1)

尝试设置依赖性transitive

implementaion ("com.bumptech.glide:glide:4.4.0@aar") {
    transitive = true
}

答案 1 :(得分:-1)

尝试更改

com.github.bumptech.glide:glide:4.4.0@aar

com.github.bumptech.glide:glide:4.4.0

有关详细信息,请参阅此https://github.com/bumptech/glide

答案 2 :(得分:-1)

Glide.with(this).load(getImage(R.drawable.a12)).into(myImageView);

public int getImage(String imageName) {

    int drawableResourceId = this.getResources().getIdentifier(imageName, "drawable", this.getPackageName());

    return drawableResourceId;
}

它适合你。