简体   繁体   English

在APK中包括以下划线(_)开头的类加载器资源

[英]Including classloader resources starting with underscore (_) in an APK

I have a library that reads a Classloader resource properties/_message.properties , though something like 我有一个读取Classloader资源properties/_message.properties ,尽管类似

this.getClass()
    .getClassLoader()
    .getResourceAsStream(
        "properties/_message.properties")

In older (Maven-based) versions of the Android build pipeline this worked fine, but it does not work with the current Gradle tools. 在较旧的(基于Maven的)Android构建管道版本中,此方法工作正常,但不适用于当前的Gradle工具。

I have tried including the file as a resource in my project, but it is only included in the APK if it does not start with an underscore: 我曾尝试将文件作为资源包含在我的项目中,但如果它不以下划线开头,则仅包含在APK中:

If I have two files src/main/resources/properties/message.properties and src/main/resources/properties/_message.properties . 如果我有两个文件src/main/resources/properties/message.propertiessrc/main/resources/properties/_message.properties

build.gradle : build.gradle

sourceSets {
    main {
        resources.srcDirs = ['src/main/resources']
    }
}

If I build the APK, it contains properties/message.properties and not properties/_message.properties . 如果我构建APK,则其中包含properties/message.properties而不是properties/_message.properties The former file is also accessible as a classloader resource. 前一个文件也可以作为类加载器资源进行访问。

There are some long-standing bugs related to this, that either claim to be fixed but aren't, or are marked WONTFIX. 有一些与此相关的长期存在的错误,它们声称已修复但尚未修复,或者被标记为WONTFIX。

The first issue includes a workaround that "[extends] the build process to add any asset files with a parent directory starting with an underscore to the debug APK after it's first assembled, and then resign the APK with the new files" . 第一个问题包括一种解决方法,该解决方法“扩展了构建过程,以在调试APK首次组装后将带有下划线的父目录的任何资产文件添加到调试APK,然后使用新文件对APK进行签名”

In summary: you can either use a workaround, or rename your resources. 总结:您可以使用解决方法,也可以重命名资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM