英文:
Why is flow emit crashing on release mode?
问题
The app keeps crashing iff it's in release mode and debuggable is set to false.
release {
minifyEnabled true
shrinkResources true
debuggable false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
Through commenting out lines of code I have traced down the issue to the line below:
emit(Resource.Success(listOf(
dayMarketChartResponse.body()!!.toMarketChartEntityList(),
threeMonthMarketChartResponse.body()!!.toMarketChartEntityList(),
yearMarketChartResponse.body()!!.toMarketChartEntityList(),
)))
Interesting points
- I have fake data of which of I use to replace any one of the 3 sublists, the app does not crash.
I am probably overlooking something obvious. If you any more information to provide more context I'll update the question.
Edit: 13 June 2023
Data classes with SerializedName
annotation for preservation through obfuscation
data class MarketChartDto(
@SerializedName("market_caps")
val marketCaps: List<List<Double>>,
@SerializedName("prices")
val prices: List<List<Double>>,
@SerializedName("total_volumes")
val totalVolumes: List<List<Double>>
)
fun MarketChartDto.toMarketChartEntityList() : List<MarketChartEntity> {
return this.prices.map {
MarketChartEntity(
price = it[1]
)
}
}
英文:
The app keeps crashing iff it's in release mode and debuggable is set to false.
release {
minifyEnabled true
shrinkResources true
debuggable false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
Through commenting out lines of code I have traced down the issue to the line below:
emit(Resource.Success(listOf(
dayMarketChartResponse.body()!!.toMarketChartEntityList(),
threeMonthMarketChartResponse.body()!!.toMarketChartEntityList(),
yearMarketChartResponse.body()!!.toMarketChartEntityList(),
)))
Interesting points
- I have fake data of which of I use to replace any one of the 3 sublists, the app does not crash.
I am probably overlooking something obvious. If you any more information to provide more context I'll update the question.
Edit: 13 June 2023
Data classes with SerializedName
annotation for preservation through obfuscation
data class MarketChartDto(
@SerializedName("market_caps")
val marketCaps: List<List<Double>>,
@SerializedName("prices")
val prices: List<List<Double>>,
@SerializedName("total_volumes")
val totalVolumes: List<List<Double>>
)
fun MarketChartDto.toMarketChartEntityList() : List<MarketChartEntity> {
return this.prices.map {
MarketChartEntity(
price = it[1]
)
}
}
答案1
得分: 0
以下是已翻译的内容:
"The credit goes to another programmer who raised a PR in the repo and here was his explanation:
Add proguard rules in app level to keep annotated class members.
R8 strips annotated members of DTO - could be fixed in concrete DTO - MarketChartDto with @keep annotation, but issue could happen with other DTOs as well
Keeps the SerializedName annotations on all fields in all classes.
This is necessary for using the Gson library to serialize and deserialize objects.
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName
}"
英文:
The credit goes to another programmer who raised a PR in the repo and here was his explanation:
> Add proguard rules in app level to keep annotated class members.
R8 strips annotated members of DTO - could be fixed in concrete DTO - MarketChartDto with @keep annotation, but issue could happen with other DTOs as well
# Keeps the SerializedName annotations on all fields in all classes.
# This is necessary for using the Gson library to serialize and deserialize objects.
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName <fields>;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论