“为什么在发布模式下 flow emit 崩溃?”

huangapple go评论79阅读模式
英文:

Why is flow emit crashing on release mode?

问题

The app keeps crashing iff it's in release mode and debuggable is set to false.

  1. release {
  2. minifyEnabled true
  3. shrinkResources true
  4. debuggable false
  5. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  6. signingConfig signingConfigs.debug
  7. }

Through commenting out lines of code I have traced down the issue to the line below:

  1. emit(Resource.Success(listOf(
  2. dayMarketChartResponse.body()!!.toMarketChartEntityList(),
  3. threeMonthMarketChartResponse.body()!!.toMarketChartEntityList(),
  4. yearMarketChartResponse.body()!!.toMarketChartEntityList(),
  5. )))

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

  1. data class MarketChartDto(
  2. @SerializedName("market_caps")
  3. val marketCaps: List<List<Double>>,
  4. @SerializedName("prices")
  5. val prices: List<List<Double>>,
  6. @SerializedName("total_volumes")
  7. val totalVolumes: List<List<Double>>
  8. )
  9. fun MarketChartDto.toMarketChartEntityList() : List<MarketChartEntity> {
  10. return this.prices.map {
  11. MarketChartEntity(
  12. price = it[1]
  13. )
  14. }
  15. }
英文:

The app keeps crashing iff it's in release mode and debuggable is set to false.

  1. release {
  2. minifyEnabled true
  3. shrinkResources true
  4. debuggable false
  5. proguardFiles getDefaultProguardFile(&#39;proguard-android-optimize.txt&#39;), &#39;proguard-rules.pro&#39;
  6. signingConfig signingConfigs.debug
  7. }

Through commenting out lines of code I have traced down the issue to the line below:

  1. emit(Resource.Success(listOf(
  2. dayMarketChartResponse.body()!!.toMarketChartEntityList(),
  3. threeMonthMarketChartResponse.body()!!.toMarketChartEntityList(),
  4. yearMarketChartResponse.body()!!.toMarketChartEntityList(),
  5. )))

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

  1. data class MarketChartDto(
  2. @SerializedName(&quot;market_caps&quot;)
  3. val marketCaps: List&lt;List&lt;Double&gt;&gt;,
  4. @SerializedName(&quot;prices&quot;)
  5. val prices: List&lt;List&lt;Double&gt;&gt;,
  6. @SerializedName(&quot;total_volumes&quot;)
  7. val totalVolumes: List&lt;List&lt;Double&gt;&gt;
  8. )
  9. fun MarketChartDto.toMarketChartEntityList() : List&lt;MarketChartEntity&gt; {
  10. return this.prices.map {
  11. MarketChartEntity(
  12. price = it[1]
  13. )
  14. }
  15. }

答案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

  1. # Keeps the SerializedName annotations on all fields in all classes.
  2. # This is necessary for using the Gson library to serialize and deserialize objects.
  3. -keepclassmembers,allowobfuscation class * {
  4. @com.google.gson.annotations.SerializedName &lt;fields&gt;;
  5. }

huangapple
  • 本文由 发表于 2023年6月13日 00:46:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76458723.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定