我正在研究Chromium fork。我如何替换Chromium资源和应用程序包?
我发现有一天android_branding_res_dirs
gn参数是introduced:
@@ -43,10 +43,10 @@
# GYP: //chrome/chrome.gyp:chrome_java (resources part)
android_resources("chrome_java_resources") {
- resource_dirs = [
- "java/res",
- "java/res_default",
- ]
+ if (!defined(android_branding_res_dirs)) {
+ android_branding_res_dirs = [ "//chrome/android/java/res_chromium" ]
+ }
+ resource_dirs = [ "java/res" ] + android_branding_res_dirs
deps = [
":chrome_locale_paks",
":chrome_strings_grd",
,然后是broken:
@@ -43,10 +43,10 @@
# GYP: //chrome/chrome.gyp:chrome_java (resources part)
android_resources("chrome_java_resources") {
- if (!defined(android_branding_res_dirs)) {
- android_branding_res_dirs = [ "//chrome/android/java/res_chromium" ]
- }
- resource_dirs = [ "java/res" ] + android_branding_res_dirs
+ resource_dirs = [
+ "java/res",
+ "//chrome/android/java/res_chromium",
+ ]
deps = [
":chrome_locale_paks",
":chrome_strings_grd",
那么添加res_myfork
目录并用res_chromium
正确方式将res_myfork
替换为chrome/android/BUILD.gn
以便现在添加fork资源吗?
我在manifest_package
中找到chrome/android/BUILD.gn
:
manifest_package = "org.chromium.chrome"
我也可以看到custom_package = "org.chromium.chrome"
:
android_resources("chrome_java_resources") {
resource_dirs = [
"java/res",
"//chrome/android/java/res_chromium", // replaced to `res_myfork`
]
...
custom_package = "org.chromium.chrome" // replaced to `org.company.myfork` by me
}
在构建我的错误时:
因为我可以在大多数java类中看到包资源命名空间是硬编码的(例如。/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/ActionItem.java
):
import org.chromium.chrome.R;
参考资源的正确方式是什么? 我应该将这些行替换为我的包资源名称空间吗? 是否有任何python脚本在构建时自动执行?
我应该替换custom_package
还是保持原样?
更新1。
我发现了一句话" Chrome"要在大多数字符串中进行硬编码,例如./chrome/android/java/strings/android_chrome_strings.grd
:
<!-- Sign-in preference -->
<message name="IDS_SIGN_IN_TO_CHROME" desc="Title for the button to sign in to Chrome using one's Google account. [CHAR-LIMIT=27]">
Sign in to Chrome
</message>
有没有办法调整它(脚本)或我应该改变它?我希望在将来合并时避免冲突,所以我正在寻找合适的方式(或者以无痛的方式)来做到这一点。
更新2。
我可以看到Brave浏览器是如何做到的: https://github.com/brave/browser-android-tabs/commit/b3fa10a7b10379c8ce5cdbeb68e3c52b580292da
https://github.com/brave/browser-android-tabs/commit/956bd321871844f72d98b9666434e5aceac7da81
这真的很好吗?
答案 0 :(得分:2)
import('package.gni')
...
chrome_public_manifest_package = manifest_package
chrome_public_test_manifest_package = test_manifest_package
创建一个package.gni
文件:
declare_args() {
manifest_package = "org.chromium.chrome"
test_manifest_package = "${manifest.package}.tests"
}
现在gn gen .. manifest_package="com.company.fork"
PS。顺便说一句,请先尝试直接覆盖chrome_public_manifest_package
,而不进行更改。