简体   繁体   中英

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

I have a library that reads a Classloader resource properties/_message.properties , though something like

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.

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:

If I have two files src/main/resources/properties/message.properties and src/main/resources/properties/_message.properties .

build.gradle :

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

If I build the APK, it contains properties/message.properties and not 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.

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" .

In summary: you can either use a workaround, or rename your resources.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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