file:///android_res/drawable not working when using flavor with other package name

前端 未结 2 1535
一整个雨季
一整个雨季 2020-12-17 17:28

My problem is that after I added flavors to my project the flavor with a package name different from the actual source seems to have problems with accessing the files in

2条回答
  •  别那么骄傲
    2020-12-17 18:18

    packageName is not supported in gradle. Gradle has a distinction between applicationId and packageName (see http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename) which means that should be able to have the resources package name differ from the package identifier for your application.

    Unfortunately that does not seem to be supported by the file:///android_res URL scheme in a webview.

    I was able to workaround it in my case by creating an R class in the other package with the correct inner class and with a public static final int field that was initialized with the value from the real R file. This is a hack and doesn't survive renaming the resource and is not convenient if you have lots of resources you need to access.

    So in your case that would look like adding this to your beta flavor source files directory:

    package com.company.beta;
    
    class R
    {
        class drawable
        {
            public static final int image = com.company.myapp.R.drawable.image;
        }
    }
    

提交回复
热议问题