Glide Version: 4.5.0, also occurs with 3.8.0
Minimal working example:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/myImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.constraint.ConstraintLayout>
import android.graphics.Bitmap
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.BitmapImageViewTarget
import kotlinx.android.synthetic.main.activity_main.*
class Changes(private val activity: MainActivity, private val url: String?) {
fun show() {
url?.let {
Glide.with(activity).asBitmap().load(url)
.into(object : BitmapImageViewTarget(activity.myImageView) {
override fun setResource(resource: Bitmap?) {
activity.myImageView.setImageBitmap(resource)
}
})
}
}
}
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Changes(
this,
"https://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/SNice.svg/1200px-SNice.svg.png"
).show()
}
}
Seems to work fine if I don't load it into an anonymous class but rather directly into an ImageView. Error thrown is this:
FATAL EXCEPTION: main
Process: com.example.felixg.myapplication, PID: 6291
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/example/felixg/myapplication/Changes$show$1$1;
at com.example.felixg.myapplication.Changes.show(MainActivity.kt:13)
at com.example.felixg.myapplication.MainActivity.onCreate(MainActivity.kt:32)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.felixg.myapplication.Changes$show$1$1" on path: DexPathList[[zip file "/data/app/com.example.felixg.myapplication-8d8bzEJbelPrtHCDz_zItg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.felixg.myapplication-8d8bzEJbelPrtHCDz_zItg==/lib/x86_64, /system/lib64, /vendor/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.example.felixg.myapplication.Changes.show(MainActivity.kt:13)聽
at com.example.felixg.myapplication.MainActivity.onCreate(MainActivity.kt:32)聽
at android.app.Activity.performCreate(Activity.java:6975)聽
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)聽
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)聽
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)聽
at android.app.ActivityThread.-wrap11(Unknown Source:0)聽
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)聽
at android.os.Handler.dispatchMessage(Handler.java:105)聽
at android.os.Looper.loop(Looper.java:164)聽
at android.app.ActivityThread.main(ActivityThread.java:6541)聽
at java.lang.reflect.Method.invoke(Native Method)聽
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)聽
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)聽
I don't think this is Glide related, it looks like there's some issue with your build where required classes aren't included. Maybe proguard?
StackOverflow might be a better place for this question.
That's what I thought at first, but in this test project, Proguard isn't enabled. However, if I add:
debug {
debuggable true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
so that Proguard _is_ enabled, I actually get a compile time error with Proguard failing to find the referenced class. I also thought it was a Kotlin issue at first but if I lift the object creation out into a separate function:
runOnInterface(object : BitmapImageViewTarget(activity.myImageView) {
override fun setResource(resource: Bitmap?) {
activity.myImageView.setImageBitmap(resource)
}
})
...
fun runOnInterface(obj: BitmapImageViewTarget) {
Glide.with(activity).asBitmap().load(url)
.into(obj)
}
It doesn't crash. Not sure the cause of this issue and where I should file. Should I make a ticket under Kotlin's tracker?
delete app/build and clear project.
This issue has been automatically marked as stale because it has not had activity in the last seven days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.
I have the exact same issue, cleaning the project does not help :(
I meet the same problem . Do you know why?
This problem still exists in the latest versions
This problem still exists in the latest versions
Agreed, this is still happening
That's what I thought at first, but in this test project, Proguard isn't enabled. However, if I add:
debug { debuggable true minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' }so that Proguard _is_ enabled, I actually get a compile time error with Proguard failing to find the referenced class. I also thought it was a Kotlin issue at first but if I lift the object creation out into a separate function:
runOnInterface(object : BitmapImageViewTarget(activity.myImageView) { override fun setResource(resource: Bitmap?) { activity.myImageView.setImageBitmap(resource) } }) ... fun runOnInterface(obj: BitmapImageViewTarget) { Glide.with(activity).asBitmap().load(url) .into(obj) }It doesn't crash. Not sure the cause of this issue and where I should file. Should I make a ticket under Kotlin's tracker?
This work around fixed the issue for me
It seems to be related to kotlin inline fun
for example:
when I use let fun like this , will get java.lang.NoClassDefFoundError
mBinding?.let {
GlideApp.with(context)
.asBitmap()
.load(data.image_urls.original)
.into(object : CustomTarget<Bitmap>() {
override fun onLoadCleared(placeholder: Drawable?) {
viewModel.cover = null
}
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
viewModel.cover = resource
it.cover.setImageBitmap(resource)
}
})
}
but if I remove let fun like this锛宔verything is ok
if (mBinding != null) {
GlideApp.with(context)
.asBitmap()
.load(data.image_urls.original)
.into(object : CustomTarget<Bitmap>() {
override fun onLoadCleared(placeholder: Drawable?) {
viewModel.cover = null
}
override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) {
viewModel.cover = resource
mBinding.cover.setImageBitmap(resource)
}
})
}
Finally, I wish anyone tell me what cause it
This problem still exists in the latest versions
Agreed, this is still happening
Did you use inline fun like mine?
It seems to be related to kotlin inline fun
for example:
when I use let fun like this , will get java.lang.NoClassDefFoundErrormBinding?.let { GlideApp.with(context) .asBitmap() .load(data.image_urls.original) .into(object : CustomTarget<Bitmap>() { override fun onLoadCleared(placeholder: Drawable?) { viewModel.cover = null } override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) { viewModel.cover = resource it.cover.setImageBitmap(resource) } }) }but if I remove let fun like this锛宔verything is ok
if (mBinding != null) { GlideApp.with(context) .asBitmap() .load(data.image_urls.original) .into(object : CustomTarget<Bitmap>() { override fun onLoadCleared(placeholder: Drawable?) { viewModel.cover = null } override fun onResourceReady(resource: Bitmap, transition: Transition<in Bitmap>?) { viewModel.cover = resource mBinding.cover.setImageBitmap(resource) } }) }Finally, I wish anyone tell me what cause it
Weird, but this work for me, thank you very much
Most helpful comment
It seems to be related to kotlin inline fun
for example:
when I use let fun like this , will get java.lang.NoClassDefFoundError
but if I remove let fun like this锛宔verything is ok
Finally, I wish anyone tell me what cause it