无法在 Kotlin 中构建发布版本

2023-12-22

将我的 Android 项目转换为 Kotlin 后,我无法构建发布版本,该错误似乎与 Proguard 有关。

我看到 155 个警告,例如

Warning:com.example.app.activity.MainActivity$1: can't find referenced field 'android.view.View decorView' in program class com.example.app.activity.MainActivity
Warning:com.example.app.activity.MainActivity$2: can't find referenced field 'android.os.Handler handler' in program class com.example.app.activity.MainActivity

并且构建失败

Error:Execution failed for task ':MyApp:transformClassesAndResourcesWithProguardForFreeRelease'.
> Job failed, see logs for details

如果我将 build.grade 中的这些指令从 true 更改为 false,则构建会成功。

minifyEnabled true
shrinkResources true

关于可能出现的问题有什么建议吗?

Edit:

proguard 文件如下:

proguard-android.txt

# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
-dontpreverify

# If you want to enable optimization, you should include the
# following:
# -optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
# -optimizationpasses 5
# -allowaccessmodification
#
# Note that you cannot just include these flags in your own
# configuration file; if you are including this file, optimization
# will be turned off. You'll need to either edit this file, or
# duplicate the contents of this file and remove the include of this
# file from your project's proguard.config path property.

-keepattributes *Annotation*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgent
-keep public class * extends android.preference.Preference
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment
-keep public class com.android.vending.licensing.ILicensingService


# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}

-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**
-dontwarn io.codetail.animation.**

proguard-rules.txt

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/francesc/droids/android-sdk-linux/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

-keep class com.nineoldandroids.** { *; }
-dontwarn io.codetail.animation.**

签名配置定义如下所示

signingConfigs {
    myConfig {
        Properties keyProps = new Properties()
        keyProps.load(new FileInputStream(file('../release.properties')))
        storeFile file(keyProps["store"])
        keyAlias keyProps["alias"]
        storePassword keyProps["storePass"]
        keyPassword keyProps["keyPass"]
    }
}

buildTypes {
    release {
        proguardFiles 'proguard-android.txt', 'proguard-rules.txt'
        minifyEnabled true
        shrinkResources true
        signingConfig signingConfigs.myConfig
    }
}

尝试添加@Keep对相关类(例如 MainActivity)进行注释,看看是否有帮助。如果是这样,则意味着 minify 正在重命名某些资源,该资源不应重命名,因为某些其他资源需要使用其原始名称。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法在 Kotlin 中构建发布版本 的相关文章

随机推荐

  • Firebird 在大型项目中的使用[关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 firebird 有哪些能力可以在重点项目中使用它 PostgreSQL 和 FireBirdSQL 哪个更好 有人知道使用 Firebird
  • 最佳实践 MVVM 将数据从一个 Activity 传递到另一个 Activity

    当前将数据从一个活动 主 传递到另一个 详细 的最佳实践是什么 一种可能的方法是拥有一个在主视图和细节视图之间共享的单一视图模型类 单击主活动中的某个项目时 所选条目将设置为视图模型 详细活动因此可以读取所选条目 因为它使用相同的视图模型
  • ESLint - 需要 let 或 const 而不是 var (no-var)

    如何在 ESlint 上禁用不鼓励使用 var 并鼓励使用 const 或 let 的规则 In your package json 假设这就是您正在使用的 包括 eslintConfig rules no var 0 no var htt
  • D语言:初始化动态多维数组最佳实践?

    只是好奇这是否是初始化动态多维数组的最佳实践D http www d programming language org index html 他们的语言参考中有一个关于数组的部分 但我不太确定它是否超出了我想要完成的目标 class Map
  • 当用户单击图表时创建 MarkerView

    我已经搜索并搜索了当用户使用 Swift 的图表 是 iOS 图表 单击条形图中的条形时如何显示 MarkerView 文档指出该库能够使用 MarkerViews 突出显示值 使用可自定义的弹出视图 但我不知道如何显示 我希望当用户单击条
  • Watin - 如何使用弹出页面测试网站

    我正在使用 WatiN Net 中的 Web 应用程序测试 在 Dynamics CRM 4 0 网站上进行集成测试 CRM 使用大量弹出窗口 例如 单击列表中的联系人会打开一个新的浏览器窗口 其中包含该联系人的详细信息 我想测试 登录 C
  • 将多个文件加载并命名到 R 中

    我有超过 1000 个数据集 我想加载到 R 中 并在加载时单独命名每个数据集 我发现要加载它们 我可以使用以下命令 temp list files pattern csv for i in 1 length temp assign tem
  • 从 OpenCV Canny 边缘检测器获取角度

    我想使用 OpenCV 的 Canny 边缘检测器 如中概述的这个问题 https stackoverflow com questions 11987483 opencvs canny edge detection in c 例如 cv C
  • 无法将类型“System.Collections.Generic.List<>”隐式转换为“System.Threading.Tasks.Task<>>”

    我遇到了例外 无法隐式转换类型 System Collections Generic List
  • 如何将日期选择器日期更改为 NSDate 类型但秒数为零

    我有一个日期选择器 它返回一个 NSdate 值 我想要将秒数的日期值设置为 0 我有在 Objective c 中执行此操作的代码 如下所示 NSTimeInterval time floor date timeIntervalSince
  • VBA Excel - ACCESS 中的更新记录

    我遇到问题了 我想使用 EXCEL 中的 VBA 更新 Access 数据库表中的现有记录 My code sqlik UPDATE query which works in access Set ZAP QUERY2 baza Creat
  • 将文本插入现有/外部 Draftjs 文本字段

    我正在开发一个需要将文本插入到contenteditable true div a Draftjs准确地说 基于文本字段 现在我知道 Draft js 使用 React 并且应该以这种方式使用 但在这种情况下 该应用程序已经存在 并且这是与
  • Angular 2 中的多个模块

    我有一个 Angular 2 应用程序 RC7 它最初是作为单个组件 但很快就以各种不同 有时完全不相关 的方式在整个项目中使用 其结果是 单个NgModule引导所有组件似乎是一个糟糕的主意 并且有大量的膨胀 我正在努力寻找一种拥有多个模
  • Azure Cosmos DB 使用基于角色的访问控制读取数据

    我在 Azure 中有一个 CosmosDB 我想授予用户读取各种集合内的数据的权限 我尝试给他们 读者 角色 这让他们知道存在 CosmosDB 并且他们可以看到一些元数据 但他们无法访问其中的数据 我为他们分配了 Cosmos DB 帐
  • Bash:有任何命令可以替换文本文件中的字符串吗?

    我有一个包含许多文本文件的目录层次结构 我想在每次特定的文本字符串出现在其中一个文件中时搜索它 并将其替换为另一个字符串 例如 我可能想将每次出现的字符串 Coke 替换为 Pepsi 有谁知道如何做到这一点 我想知道是否有某种 Bash
  • Angular 2 路由器 - CanActivate Guard

    我正在实现 CanActivate 防护 以便在用户会话无效时将用户重定向到登录页面 关于会话是否有效的检查是通过服务完成的 因此我从警卫那里订阅服务调用以获取会话有效性状态 我已经调试了代码 一切似乎都正常工作 事实上 当会话无效时 应用
  • 使用另一个文件中的行范围替换单独文件中字符串中出现的每 2 个 n

    我有三个文件 0 txt e 0 1 txt具有以下相同内容 sun t car snif house group tree home cool t machine shoes shirt shop t car snif house gro
  • 在设备上安装 Windows Phone 应用程序的不同方法

    我开发了一个Windows Phone 8应用程序 我有一个开发者帐户和解锁的设备 现在我可以通过 Windows Phone 开发 sdk 在我的手机中部署 安装应用程序 现在我想在另一个设备上安装这个应用程序 我朋友的设备 他在不同的位
  • 如何在 Netbeans 中打开“项目”面板

    在 Netbeans 中 代码所在的左上角曾经有两个面板 一个称为 项目 您可以在其中单击项目名称以打开其中所有目录和文件的树 然后可以双击一个文件来编辑它 下面是导航面板 显示您正在查看的文件中包含的类名称 方法等 我不小心单击了项目面板
  • 无法在 Kotlin 中构建发布版本

    将我的 Android 项目转换为 Kotlin 后 我无法构建发布版本 该错误似乎与 Proguard 有关 我看到 155 个警告 例如 Warning com example app activity MainActivity 1 c