#android #bazel #kotlin-coroutines
#Android #базел #kotlin-сопрограммы
Вопрос:
Невозможно создать демонстрационную версию Android с помощью Bazel, когда включен параметр proguard_specs.
Журнал ошибок:
...
Warning: kotlinx.coroutines.flow.internal.ChannelFlowMerge$collectTo$inlined$collect$1$lambda$1: can't find enclosing method 'java.lang.Object emit$forInline(java.lang.Object,kotlin.coroutines.Continuation)' in program class kotlinx.coroutines.flow.internal.ChannelFlowMerge$collectTo$inlined$collect$1
Warning: kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$invokeSuspend$inlined$collect$1$1: can't find enclosing method 'java.lang.Object emit$forInline(java.lang.Object,kotlin.coroutines.Continuation)' in program class kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$invokeSuspend$inlined$collect$1
Warning: kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$invokeSuspend$inlined$collect$1$lambda$1: can't find enclosing method 'java.lang.Object emit$forInline(java.lang.Object,kotlin.coroutines.Continuation)' in program class kotlinx.coroutines.flow.internal.ChannelFlowTransformLatest$flowCollect$3$invokeSuspend$inlined$collect$1
Warning: kotlinx.coroutines.flow.internal.CombineKt$zipImpl$inlined$unsafeFlow$1$lambda$1: can't find enclosing method 'java.lang.Object collect$forInline(kotlinx.coroutines.flow.FlowCollector,kotlin.coroutines.Continuation)' in program class kotlinx.coroutines.flow.internal.CombineKt$zipImpl$inlined$unsafeFlow$1
Warning: kotlinx.coroutines.flow.internal.FlowCoroutineKt$scopedFlow$inlined$unsafeFlow$1$lambda$1: can't find enclosing method 'java.lang.Object collect$forInline(kotlinx.coroutines.flow.FlowCollector,kotlin.coroutines.Continuation)' in program class kotlinx.coroutines.flow.internal.FlowCoroutineKt$scopedFlow$inlined$unsafeFlow$1
Warning: there were 2 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 51 unresolved references to program class members.
Your input classes appear to be inconsistent.
You may need to recompile the code.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedprogramclassmember)
Error: Please correct the above warnings first.
ProGuard, version 5.3.3
...
Note: kotlinx.coroutines.CommonPool accesses a method 'getPoolSize()' dynamically
Maybe this is library method 'java.util.concurrent.ForkJoinPool { int getPoolSize(); }'
Maybe this is library method 'java.util.concurrent.ThreadPoolExecutor { int getPoolSize(); }'
Note: there were 5 classes trying to access annotations using reflection.
You should consider keeping the annotation attributes
(using '-keepattributes *Annotation*').
(http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 4 classes trying to access generic signatures using reflection.
You should consider keeping the signature attributes
(using '-keepattributes Signature').
(http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 2 classes trying to access enclosing methods using reflection.
You should consider keeping the enclosing method attributes
(using '-keepattributes InnerClasses,EnclosingMethod').
(http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 15 unresolved dynamic references to classes or interfaces.
You should check if you need to specify additional program jars.
(http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass)
Note: there were 29 accesses to class members by means of introspection.
You should consider explicitly keeping the mentioned class members
(using '-keep' or '-keepclassmembers').
(http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclassmember)
Target //app/src/main:app failed to build
INFO: Elapsed time: 3.238s, Critical Path: 3.10s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully
Конфигурация Bazel:
android_binary(
name = "app",
manifest = "AndroidManifest.xml",
custom_package = "felix.duan.androidnavisample",
manifest_values = {
"minSdkVersion": "21",
"versionCode" : "2",
"versionName" : "2.0",
"targetSdkVersion" : "29",
},
proguard_generate_mapping = True,
proguard_specs = ["proguard-rules.pro"],
deps = [
":lib",
]
)
proguard-rules.pro:
-keep class org.jetbrains.annotations.** { *; }
-dontwarn org.jetbrains.annotations.**
Инструменты сборки:
bazel: v3.7.0-homebrew
rules_kotlin_version: legacy-1.4.0-rc4
android sdk: v30.0.2
Вопрос А: Как решить эту проблему?
дополнительные вопросы, которые я нашел, связанные с этим:
Вопрос B: использует ли Bazel proguard транзитивных зависимостей?Если нет, это может быть причиной?
Вопрос C: Поддерживает ли Bazel R8? Я не нашел прямой информации об этом.
Ответ №1:
Поскольку это всего лишь предупреждение, возможно, вы можете отключить его в конфигурации proguard:
-dontwarn kotlinx.coroutines.**
И затем ошибка, которая является ошибкой: пожалуйста, сначала исправьте приведенные выше предупреждения. может исчезнуть.