bumptech / bumptech/glide

Is there a way to fork glide then build it via JitPack? - To debug and solve AppWidgetTarget crash issue in Android 11

Open
#4,361 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
35k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
8

Description

**Glide Version**:
4.11.0

**Integration libraries**:

**Device/Android Version**:
Emulator Android 11

**Issue details / Repro steps / Use case background**:
We experience 100% crash report in live Android 11

The previous code works 100% before Android 11 (Even though sometimes image may not displayed in home widget - https://github.com/bumptech/glide/issues/396 . But that is another issue)

We would like to fork glide project, then insert some logging code, and perhaps some try...catch block as temporary hotfix to such issue. However, we notice glide project doesn't work well with jitpack.

We trigger build process in jitpack server by using

```
implementation 'com.github.yccheok:glide:fork-SNAPSHOT'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
```

When it is built in jitpack server - https://jitpack.io/com/github/yccheok/glide/fork-f05dc60714-1/build.log

We are getting

```
A problem occurred evaluating project ':integration:concurrent'.
> Failed to apply plugin [id 'com.android.library']
> Your project contains 2 or more modules with the same identification com.github.yccheok:test
at ":library:test" and ":annotation:compiler:test".
You must use different identification (either name or group) for each modules.
```

**Glide load line / `GlideModule` (if any) / list Adapter code (if any)**:
```java
private static void loadImage(Context context, AppWidgetManager appWidgetManager, RemoteViews rowRemoteViews, int appWidgetId, Attachment attachment, int imageViewResourceId) {
final Pair bestSize = getBestSizeForWidget(attachment);

AppWidgetTarget awt = new AppWidgetTarget(context, imageViewResourceId, rowRemoteViews, appWidgetId);

final CountDownLatch countDownLatch = new CountDownLatch(1);

// Glide requires .into called in main thread.
Runnable runnable = () -> {
try {
Glide.with(context)
.asBitmap()
.load(attachment.getPath())
.apply(new RequestOptions().override(bestSize.first, bestSize.second))
.listener(new RequestListener() {
@Override
public boolean onLoadFailed(@Nullable final GlideException e, final Object model,
final Target target, final boolean isFirstResource) {
return updateRowWidget();
}

@Override
public boolean onResourceReady(final Bitmap resource, final Object model, final Target target,
final DataSource dataSource, final boolean isFirstResource) {
return updateRowWidget();
}

private boolean updateRowWidget() {
try {
appWidgetManager.updateAppWidget(appWidgetId, rowRemoteViews);
} catch (java.lang.NullPointerException e) {
trackEvent(TAG, "loadImage", "fatal");
}
return false;
}
}).into(awt);
} finally {
countDownLatch.countDown();
}
};

runInMainThread(runnable);

// If we return without waiting .into(awt) to be executed, it just wouldn't work.
try {
countDownLatch.await();
} catch (InterruptedException e) {
Log.e(TAG, "", e);
}
}
```

**Layout XML**:

```
2020-10-01 19:03:59.263 14787-14787/com.yocto.wenote E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.yocto.wenote, PID: 14787
com.bumptech.glide.load.engine.CallbackException: Unexpected exception thrown by non-Glide code
at com.bumptech.glide.load.engine.EngineJob.callCallbackOnResourceReady(EngineJob.java:160)
at com.bumptech.glide.load.engine.EngineJob$CallResourceReady.run(EngineJob.java:424)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.util.ArrayMap.get(java.lang.Object)' on a null object reference
at android.os.Parcel.createExceptionOrNull(Parcel.java:2379)
at android.os.Parcel.createException(Parcel.java:2357)
at android.os.Parcel.readException(Parcel.java:2340)
at android.os.Parcel.readException(Parcel.java:2282)
at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.updateAppWidgetIds(IAppWidgetService.java:977)
at android.appwidget.AppWidgetManager.updateAppWidget(AppWidgetManager.java:531)
at com.bumptech.glide.request.target.AppWidgetTarget.update(AppWidgetTarget.java:124)
at com.bumptech.glide.request.target.AppWidgetTarget.setBitmap(AppWidgetTarget.java:141)
at com.bumptech.glide.request.target.AppWidgetTarget.onResourceReady(AppWidgetTarget.java:131)
at com.bumptech.glide.request.target.AppWidgetTarget.onResourceReady(AppWidgetTarget.java:22)
at com.bumptech.glide.request.SingleRequest.onResourceReady(SingleRequest.java:631)
at com.bumptech.glide.request.SingleRequest.onResourceReady(SingleRequest.java:575)
at com.bumptech.glide.load.engine.EngineJob.callCallbackOnResourceReady(EngineJob.java:158)
```

Do you have any idea, for us to fork glide then build it via JitPack? Thanks.

---

**Compile to JAR file locally**

An alternative way I had tried is by building jar file manually using command

`gradlew jar`

Then I use the following in build.gradle

```
//implementation 'com.github.bumptech.glide:glide:4.11.0'
implementation files('C:\\yocto\\glide.git\\glide\\build\\libs\\glide-full-4.11.0.jar')
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
```

The compilation is fine. However, when I run the app, I will be getting the following error

`Caused by: java.lang.ClassNotFoundException: Didn't find class "com.bumptech.glide.R$id"`

---

**JitPack**

I have performed module renaming from `:annotation:compiler:test` to `:annotation:compiler:tests` - https://github.com/yccheok/glide/commit/aff4c4b05eb91542137258569b280e33dc6abfdc , so that JitPack server can build without issue - https://jitpack.io/com/github/yccheok/glide/fork-aff4c4b05e-1/build.log

I then use

```
implementation 'com.github.yccheok:glide:fork-SNAPSHOT'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
```

Then, I am getting error during compiling

```
Duplicate class com.bumptech.glide.annotation.Excludes found in modules jetified-annotation-fork-SNAPSHOT.jar (com.github.yccheok.glide:annotation:fork-SNAPSHOT:aff4c4b05e-1) and jetified-annotations-4.11.0.jar (com.github.bumptech.glide:annotations:4.11.0)
Duplicate class com.bumptech.glide.annotation.GlideExtension found in modules jetified-annotation-fork-SNAPSHOT.jar (com.github.yccheok.glide:annotation:fork-SNAPSHOT:aff4c4b05e-1) and jetified-annotations-4.11.0.jar (com.github.bumptech.glide:annotations:4.11.0)
Duplicate class com.bumptech.glide.annotation.GlideModule found in modules jetified-annotation-fork-SNAPSHOT.jar (com.github.yccheok.glide:annotation:fork-SNAPSHOT:aff4c4b05e-1) and jetified-annotations-4.11.0.jar (com.github.bumptech.glide:annotations:4.11.0)
Duplicate class com.bumptech.glide.annotation.GlideOption found in modules jetified-annotation-fork-SNAPSHOT.jar (com.github.yccheok.glide:annotation:fork-SNAPSHOT:aff4c4b05e-1) and jetified-annotations-4.11.0.jar (com.github.bumptech.glide:annotations:4.11.0)
Duplicate class com.bumptech.glide.annotation.GlideType found in modules jetified-annotation-fork-SNAPSHOT.jar (com.github.yccheok.glide:annotation:fork-SNAPSHOT:aff4c4b05e-1) and jetified-annotations-4.11.0.jar (com.github.bumptech.glide:annotations:4.11.0)
Duplicate class com.bumptech.glide.annotation.compiler.Index found in modules jetified-annotation-fork-SNAPSHOT.jar (com.github.yccheok.glide:annotation:fork-SNAPSHOT:aff4c4b05e-1) and jetified-annotations-4.11.0.jar (com.github.bumptech.glide:annotations:4.11.0)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.