Skip to content

Commit

Permalink
fix: Extensions disappearing due to errors with the ClassLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
jmir1 committed Jul 1, 2024
1 parent 5045fa1 commit 959f84a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
applicationId = "xyz.jmir.tachiyomi.mi"

versionCode = 124
versionName = "0.16.4.2"
versionName = "0.16.4.3"

buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"")
buildConfigField("String", "COMMIT_SHA", "\"${getGitSha()}\"")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Build
import androidx.core.content.pm.PackageInfoCompat
import dalvik.system.PathClassLoader
import eu.kanade.domain.extension.anime.interactor.TrustAnimeExtension
import eu.kanade.domain.source.service.SourcePreferences
import eu.kanade.tachiyomi.animesource.AnimeCatalogueSource
Expand Down Expand Up @@ -306,6 +307,26 @@ internal object AnimeExtensionLoader {
is AnimeSourceFactory -> obj.createSources()
else -> throw Exception("Unknown source class type: ${obj.javaClass}")
}
} catch (e: LinkageError) {
try {
val fallBackClassLoader = PathClassLoader(appInfo.sourceDir, null, context.classLoader)
when (
val obj = Class.forName(
it,
false,
fallBackClassLoader
).getDeclaredConstructor().newInstance()
) {
is AnimeSource -> {
listOf(obj)
}
is AnimeSourceFactory -> obj.createSources()
else -> throw Exception("Unknown source class type: ${obj.javaClass}")
}
} catch (e: Throwable) {
logcat(LogPriority.ERROR, e) { "Extension load error: $extName ($it)" }
return AnimeLoadResult.Error
}
} catch (e: Throwable) {
logcat(LogPriority.ERROR, e) { "Extension load error: $extName ($it)" }
return AnimeLoadResult.Error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.os.Build
import androidx.core.content.pm.PackageInfoCompat
import dalvik.system.PathClassLoader
import eu.kanade.domain.extension.manga.interactor.TrustMangaExtension
import eu.kanade.domain.source.service.SourcePreferences
import eu.kanade.tachiyomi.extension.manga.model.MangaExtension
Expand Down Expand Up @@ -316,6 +317,26 @@ internal object MangaExtensionLoader {
is SourceFactory -> obj.createSources()
else -> throw Exception("Unknown source class type: ${obj.javaClass}")
}
} catch (e: LinkageError) {
try {
val fallBackClassLoader = PathClassLoader(appInfo.sourceDir, null, context.classLoader)
when (
val obj = Class.forName(
it,
false,
fallBackClassLoader
).getDeclaredConstructor().newInstance()
) {
is MangaSource -> {
listOf(obj)
}
is SourceFactory -> obj.createSources()
else -> throw Exception("Unknown source class type: ${obj.javaClass}")
}
} catch (e: Throwable) {
logcat(LogPriority.ERROR, e) { "Extension load error: $extName ($it)" }
return MangaLoadResult.Error
}
} catch (e: Throwable) {
logcat(LogPriority.ERROR, e) { "Extension load error: $extName ($it)" }
return MangaLoadResult.Error
Expand Down

0 comments on commit 959f84a

Please sign in to comment.