Fixed
Status Update
Comments
zi...@gmail.com <zi...@gmail.com> #2
Same here. I have links in a local html file referencing file:///android_res/drawable/ and on all gradle build flavors using another applicationId (added suffix) the Webview only shows broken links.
This behaviour seems not to be connected solely to Android 5.0 since it occurs on Android 4.4.4 too (tested with current cyanogenmod 11 build).
This behaviour seems not to be connected solely to Android 5.0 since it occurs on Android 4.4.4 too (tested with current cyanogenmod 11 build).
zi...@gmail.com <zi...@gmail.com> #3
As a hotfix I added the following code to the gradle buildscript, which generates an additional R.java with changed java package for every flavor. I don't like this solution though.
android.applicationVariants.all{ variant ->
variant.javaCompile.doFirst{
copy {
from "${buildDir}/generated/source/r/${variant.dirName}/com/example/application/R.java"
into "${buildDir}/generated/source/r/${variant.dirName}/com/example/application/${variant.buildType.name }/"
}
File rFile = file("${buildDir}/generated/source/r/${variant.dirName}/com/example/application/${variant.buildType.name }/R.java")
String content = rFile.getText('UTF-8')
String newPackageName = "com.example.application.${variant.buildType.name }";
content = content.replaceAll(/com.example.application/, newPackageName)
rFile.write(content, 'UTF-8')
}
}
android.applicationVariants.all{ variant ->
variant.javaCompile.doFirst{
copy {
from "${buildDir}/generated/source/r/${variant.dirName}/com/example/application/R.java"
into "${buildDir}/generated/source/r/${variant.dirName}/com/example/application/${
}
File rFile = file("${buildDir}/generated/source/r/${variant.dirName}/com/example/application/${
String content = rFile.getText('UTF-8')
String newPackageName = "com.example.application.${
content = content.replaceAll(/com.example.application/, newPackageName)
rFile.write(content, 'UTF-8')
}
}
ca...@gmail.com <ca...@gmail.com> #4
I've recenly encountered this issue and I must say it's quite a nuisance. Searched half of the Internet just to find out that the problem lies in Gradle's applicationIdSuffix :). I think this bug should be reported to Android SDK Build Tools devs, because only they can do something about it.
ka...@gmail.com <ka...@gmail.com> #5
IMHO it's the case of Android platform problem. Resources are packed, WebView tries to load them from wrong place. It's not build tools that put them in wrong place.
And by the way it's very frustrating bug.
And by the way it's very frustrating bug.
mi...@gmail.com <mi...@gmail.com> #6
[Comment deleted]
mi...@gmail.com <mi...@gmail.com> #7
[Comment deleted]
st...@googlemail.com <st...@googlemail.com> #8
The applicationIdSuffix/packageName/etc seem to be a Gradle-specific concept that applies only at build time.
At runtime, the only way WebView has to identify your app is the actual package name of the APK, and that will be the full string with the suffix included. The package that was used at compile time when generating the R class is not stored in the APK, and there's not really any way for WebView to know what it was as far as I know.
At runtime, the only way WebView has to identify your app is the actual package name of the APK, and that will be the full string with the suffix included. The package that was used at compile time when generating the R class is not stored in the APK, and there's not really any way for WebView to know what it was as far as I know.
[Deleted User] <[Deleted User]> #9
[Comment deleted]
co...@gmail.com <co...@gmail.com> #10
Isn't the package name attribute in the root node of the AndroidManifest preserved when an app is packaged? That would be the correct package to use when loading the R class
hi...@gmail.com <hi...@gmail.com> #11
I don't think so. You could check what's actually in your packaged APK with "aapt dump xmltree <apkfilename> AndroidManifest.xml" - if it's not there, then WebView can't get to it at runtime either.
I haven't actually checked this as I don't have an android studio project handy currently (will try soon) but I suspect that Gradle passes the app name with the suffix appended to aapt with --package-name, which causes aapt to replace the name specified in your manifest with the one on the command line. The original name doesn't end up in the APK at all.
I haven't actually checked this as I don't have an android studio project handy currently (will try soon) but I suspect that Gradle passes the app name with the suffix appended to aapt with --package-name, which causes aapt to replace the name specified in your manifest with the one on the command line. The original name doesn't end up in the APK at all.
fa...@gmail.com <fa...@gmail.com> #12
OK, I tried this out in Gradle to check what the terms that it uses really correspond to when building a package, and also read the docs at http://tools.android.com/tech-docs/new-build-system/applicationid-vs-packagename
This has confirmed what I wrote in my previous comments, unfortunately. What Gradle calls the package name (the name of the package that your Java sources and R class are stored in) is *not* the APK's actual package name that gets set at build time, and is *not* stored anywhere at all or accessible at runtime whatsoever. The APK is solely identified by the application ID with the suffix added, and the original package name is overwritten in the manifest. Android itself does not have this concept of the package name and application ID being separate; it's just a build-time trick Gradle is doing for you.
So, unfortunately, it doesn't look like there is any way for WebView to reliably know where your R class is. We might be able to add an API for the app to specify this in a future version (though I'm not entirely sure how that would actually work; it'd probably have to be a static method on WebView?), but that won't help you for existing OS versions, we can't add new APIs retroactively.
I think your only short-term options are to not use applicationIdSuffix or to not use file:///android_res/ in WebView. You could instead use a different URL (one that isn't handled by WebView itself), intercept it with shouldInterceptRequest, and provide the data by reading it from your resources yourself. I understand that that's not very convenient, but it seems like the only actual option here that works right now.
One thing WebView could do which would work in *some* cases is to just try to strip off components from the package name if the R class isn't found, going up one package at a time until we find it. That would work if you've just added a suffix like ".debug" - we'd fail to find com.example.debug.R and then try com.example.R instead. That still wouldn't work for any case where the package name is totally different, though (which gradle permits you to do). I'll look into whether this is safe to do and if so we could maybe add this in a future webview update, but it still won't fix the problem for users of pre-Lollipop Android versions (who don't get WebView updates), or for users who just don't have the latest webview update installed, so you're going to have to work around this problem in your app anyway to continue supporting those devices. :/
This has confirmed what I wrote in my previous comments, unfortunately. What Gradle calls the package name (the name of the package that your Java sources and R class are stored in) is *not* the APK's actual package name that gets set at build time, and is *not* stored anywhere at all or accessible at runtime whatsoever. The APK is solely identified by the application ID with the suffix added, and the original package name is overwritten in the manifest. Android itself does not have this concept of the package name and application ID being separate; it's just a build-time trick Gradle is doing for you.
So, unfortunately, it doesn't look like there is any way for WebView to reliably know where your R class is. We might be able to add an API for the app to specify this in a future version (though I'm not entirely sure how that would actually work; it'd probably have to be a static method on WebView?), but that won't help you for existing OS versions, we can't add new APIs retroactively.
I think your only short-term options are to not use applicationIdSuffix or to not use file:///android_res/ in WebView. You could instead use a different URL (one that isn't handled by WebView itself), intercept it with shouldInterceptRequest, and provide the data by reading it from your resources yourself. I understand that that's not very convenient, but it seems like the only actual option here that works right now.
One thing WebView could do which would work in *some* cases is to just try to strip off components from the package name if the R class isn't found, going up one package at a time until we find it. That would work if you've just added a suffix like ".debug" - we'd fail to find com.example.debug.R and then try com.example.R instead. That still wouldn't work for any case where the package name is totally different, though (which gradle permits you to do). I'll look into whether this is safe to do and if so we could maybe add this in a future webview update, but it still won't fix the problem for users of pre-Lollipop Android versions (who don't get WebView updates), or for users who just don't have the latest webview update installed, so you're going to have to work around this problem in your app anyway to continue supporting those devices. :/
ga...@gmail.com <ga...@gmail.com> #13
I've filed http://crbug.com/599869 to track potentially handling the suffix case in the WebView code, but note that as I said, this will only fix it for users with the latest WebView on Android 5.0+ devices, and so you will need to still work around this in your application if you want it to work on any other devices.
ga...@gmail.com <ga...@gmail.com> #14
#11 thanks for explanation
I think the whole scheme file:///android_res/ ideally should be deprecated in favor to android.content.ContentResolver.SCHEME_ANDROID_RESOURCE, which allows specify package and resId and used everywhere in Android except WebView.
http://androidbook.blogspot.ru/2009/08/referring-to-android-resources-using.html
http://stackoverflow.com/a/4855376/1430070
What do you think?
I think the whole scheme file:///android_res/ ideally should be deprecated in favor to android.content.ContentResolver.SCHEME_ANDROID_RESOURCE, which allows specify package and resId and used everywhere in Android except WebView.
What do you think?
ja...@gmail.com <ja...@gmail.com> #15
Perhaps, but again, we can't add that for existing users without updatable WebView versions, so even if we did add it, it wouldn't really solve the problem for your apps since ~2/3 of the android device population doesn't get webview updates yet: http://developer.android.com/about/dashboards/index.html
no...@gmail.com <no...@gmail.com> #16
WebView 53 and onward will attempt to strip package name components from the app package name until it finds an R class, which will deal with the simplest cases here (applicationIdSuffix appending a suffix to the base name), but not other cases where the package name is unrelated to the R class name.
This won't fix it for users with pre-L android versions, or who don't upgrade to at least WebView 53 once it's released, though, so you will not be able to rely on this as a full workaround :/
This won't fix it for users with pre-L android versions, or who don't upgrade to at least WebView 53 once it's released, though, so you will not be able to rely on this as a full workaround :/
jh...@themeetgroup.com <jh...@themeetgroup.com> #17
Awesome! That updatable webview is one of the best thing you guys have done is the last couple of years!
ra...@gmail.com <ra...@gmail.com> #18
Well, this doesn't really solve your actual problem (for years yet), as I said, since there's still a significant population of pre-L devices that you probably want to keep supporting, and not all L+ devices will ever get upgraded to a sufficiently recent WebView, but yes, the fact that we can do this at all is useful :)
as...@gmail.com <as...@gmail.com> #19
Well I my problem was with dev build, and I do most of the development on
L+ devices so, it might not solve the real issue, but it is sufficient for
me :)
L+ devices so, it might not solve the real issue, but it is sufficient for
me :)
fr...@gmail.com <fr...@gmail.com> #20
[Comment deleted]
[Deleted User] <[Deleted User]> #21
ps...@gmail.com <ps...@gmail.com> #22
I'm fixing this upstream on https://crbug.com/599869 .
I'm going to close this bug as we aren't planning to do anything further to address this issue beyond the change made some time ago in #16 (and fixing it again after it broke in a more recent version)
I'm going to close this bug as we aren't planning to do anything further to address this issue beyond the change made some time ago in #16 (and fixing it again after it broke in a more recent version)
en...@gmail.com <en...@gmail.com> #24
طوفان
sa...@gmail.com <sa...@gmail.com> #25
طوفان
zh...@gmail.com <zh...@gmail.com> #26
android { defaultConfig { applicationId "com.example.myapp" minSdkVersion 15 targetSdkVersion 24 versionCode 1 versionName "1.0" } ... android { defaultConfig { applicationId "com.example.myapp" minSdkVersion 15 targetSdkVersion 24 versionCode 1 versionName "1.0" } All this is fraud and money was stolen
am...@gmail.com <am...@gmail.com> #27
Issue solved
to...@gmail.com <to...@gmail.com> #28
Good
to...@gmail.com <to...@gmail.com> #29
Thank you so much.
me...@gmail.com <me...@gmail.com> #30
That's
sh...@gmail.com <sh...@gmail.com> #31
i also want this feature
th...@gmail.com <th...@gmail.com> #32
Please stop the "me too" comments. If you want the feature too, just star the issue otherwise 100-odd people who have stared the issue get pointless emails.
mo...@gmail.com <mo...@gmail.com> #33
[Comment deleted]
mo...@gmail.com <mo...@gmail.com> #34
it's the worst issue ever. OMG there are devices running marshmallow (API Level 23) and this issue isn't resolved yet!
Do you believe 23 ?
Come on Google
Do you believe 23 ?
Come on Google
ge...@gmail.com <ge...@gmail.com> #35
Thanks, it does the job ;)
jo...@gmail.com <jo...@gmail.com> #36
While I can appreciate any technical resistance to this, people need it, and they are doing it regardless, the dirty way. Please give us a clean way to do this :)
ka...@gmail.com <ka...@gmail.com> #37
I need customized font feature for android development
yo...@gmail.com <yo...@gmail.com> #38
Please add this feature.. I really need it
sa...@gmail.com <sa...@gmail.com> #39
Author here again - PLEASE stop with the 'me too' emails - just star the issue to show your support
Every comment here e-mails EVERY person who has starred the issue - that's 229 e-mails (at current count) you are generating.
(and apologies for yet another e-mail)
Every comment here e-mails EVERY person who has starred the issue - that's 229 e-mails (at current count) you are generating.
(and apologies for yet another e-mail)
to...@gmail.com <to...@gmail.com> #40
me too :)
(btw, would be very great to specify which XMLs you want to add the font -> like: layout xml, manifest or style.xml)
For AppWide I would definitely prefer within the Manifest.
(btw, would be very great to specify which XMLs you want to add the font -> like: layout xml, manifest or style.xml)
For AppWide I would definitely prefer within the Manifest.
me...@gmail.com <me...@gmail.com> #41
yes i need this so much
[Deleted User] <[Deleted User]> #42
i cant believe why we dont have this feature yet, why making life harder google?
What is the disadvantage of letting this happen?
What is the disadvantage of letting this happen?
ed...@googlemail.com <ed...@googlemail.com> #43
[Comment deleted]
kh...@gmail.com <kh...@gmail.com> #44
Android should use many good practices employed by Windows which ease the process of software UI development. Especially, changing font in Android is very problematic. The ideal form is to setup/change the font in the XML file layout. Unfortunately, sometimes Google likes being different by making life harder.
gu...@gmail.com <gu...@gmail.com> #45
Facing the same issue, commom google, fix it
ab...@gmail.com <ab...@gmail.com> #46
please add custom font feature
f....@gmail.com <f....@gmail.com> #47
if you are not going to add it, at least explain why
su...@gmail.com <su...@gmail.com> #48
Guys please make android more beautiful by adding support for custom fonts. We are expecting this happen soon.
sy...@gmail.com <sy...@gmail.com> #49
PLease implement
m1...@gmail.com <m1...@gmail.com> #51
Thank you guys!!!
dn...@google.com <dn...@google.com> #52
Closing as per the comment #50 .
Description
supply all required information.
Font choice has always been really lacking in Android, especially when compared to iOS. Using custom fonts has also never been easy. I'd really like to set a custom font from XML. A really common requirement I have for apps (and I see this in other apps too) is to change the font used in the action bar. A suitable tag in my text style would be a good interface for this.