如何为 android 添加对铬的新依赖?
how to add new dependency for android to chromium?
我想为 android 构建 Chromium,我想向 Chromium 添加新的依赖项 Amplitude
。所以我将 third_party/android_deps/build.gradle 文件更改为:
dependencies {
...
compile 'com.amplitude:android-sdk:2.23.2'
...
}
然后从 third_party/android_deps/README.md 我 运行 这个命令来获取依赖项。
python third_party/android_deps/fetch_all.py --build-dir out/Default --android-deps-dir third_party/android_deps/ --ignore-vulnerabilities --ignore-licenses
执行 运行 命令后,此目录已添加到 third_party
目录。
third_party/android_deps/libs/com_amplitude_android_sdk/
third_party/android_deps/libs/com_squareup_okhttp3_okhttp/
third_party/android_deps/libs/com_squareup_okio_okio/
这些行已添加到 third_party/android_deps/BUILD.gn:
# This is generated, do not edit. Update BuildConfigGenerator.groovy instead.
java_prebuilt("com_amplitude_android_sdk_java") {
jar_path = "libs/com_amplitude_android_sdk/android-sdk-2.23.2.jar"
output_name = "com_amplitude_android_sdk"
supports_android = true
deps = [ ":com_squareup_okhttp3_okhttp_java" ]
}
# This is generated, do not edit. Update BuildConfigGenerator.groovy instead.
java_prebuilt("com_squareup_okhttp3_okhttp_java") {
jar_path = "libs/com_squareup_okhttp3_okhttp/okhttp-3.10.0.jar"
output_name = "com_squareup_okhttp3_okhttp"
supports_android = true
# To remove visibility constraint, add this dependency to
# //third_party/android_deps/build.gradle.
visibility = [
":*",
"//third_party/androidx:*",
]
deps = [ ":com_squareup_okio_okio_java" ]
}
# This is generated, do not edit. Update BuildConfigGenerator.groovy instead.
java_prebuilt("com_squareup_okio_okio_java") {
jar_path = "libs/com_squareup_okio_okio/okio-1.14.0.jar"
output_name = "com_squareup_okio_okio"
supports_android = true
# To remove visibility constraint, add this dependency to
# //third_party/android_deps/build.gradle.
visibility = [
":*",
"//third_party/androidx:*",
]
}
这些行也被添加到 third_party/android_deps/additional_readme_paths.json
[
...
"libs/com_amplitude_android_sdk",
...
"libs/com_squareup_okhttp3_okhttp",
"libs/com_squareup_okio_okio",
...
]
但我无法导入 com.amplitude.api.Amplitude
。我将此行添加到 chrome/android/java/src/org/chromium/chrome/browser/firstrun/FirstRunActivity.java:
import com.amplitude.api.Amplitude;
我收到这个错误:
FAILED: obj/chrome/android/chrome_java.javac.jar obj/chrome/android/chrome_java.javac.jar.info
python3 ../../build/android/gyp/compile_java.py --depfile=gen/chrome/android/chrome_java__compile_java.d --generated-dir=gen/chrome/android/chrome_java/generated_java --jar-path=obj/chrome/android/chrome_java.javac.jar --java-srcjars=\[\"gen/chrome/android/autofill_verification_status_generated_enum.srcjar\",\ \"gen/chrome/android/chrome_android_java_enums_srcjar.srcjar\",\ \"gen/chrome/android/chrome_android_java_google_api_keys_srcjar.srcjar\",\ \"gen/chrome/android/chrome_strict_mode_switch.srcjar\",\ \"gen/chrome/android/resource_id_javagen.srcjar\",\ \"gen/chrome/android/sync_user_settings_enums_java.srcjar\",\ \"gen/chrome/android/vr_build_config.srcjar\",\ \"gen/chrome/assist_ranker_prediction_enum_javagen.srcjar\",\ \"gen/chrome/instant_apps_reasons_enum_javagen.srcjar\",\ \"gen/chrome/offline_pages_enum_javagen.srcjar\",\ \"gen/chrome/partner_bookmarks_javagen.srcjar\",\ \"gen/chrome/quick_action_category_enum_javagen.srcjar\",\ \"gen/chrome/supervised_user_url_filter_enum_javagen.srcjar\",\ \"gen/chrome/browser/screenshot_mode_enum.srcjar\",\ \"gen/chrome/browser/sharing_dialog_type_generated_enum.srcjar\",\ \"gen/chrome/browser/sharing_send_message_result_generated_enum.srcjar\",\ \"gen/chrome/browser/survey_http_client_type_enum.srcjar\",\ \"gen/chrome/browser/notifications/scheduler/public/jni_enums.srcjar\",\ \"gen/chrome/browser/supervised_user/supervised_user_error_page/enums_srcjar.srcjar\",\ \"gen/components/autofill_assistant/browser/autofill_assistant_enums_java.srcjar\",\ \"gen/components/autofill_assistant/browser/autofill_assistant_intent_strings_java.srcjar\",\ \"gen/components/browsing_data/core/browsing_data_utils_java.srcjar\",\ \"gen/components/browsing_data/core/clear_browsing_data_tab_java.srcjar\",\ \"gen/components/data_reduction_proxy/core/browser/data_reduction_proxy_savings_cleared_enum_java.srcjar\",\ \"gen/components/dom_distiller/core/distiller_type_java.srcjar\",\ \"gen/components/ntp_tiles/ntp_tiles_enums_java.srcjar\",\ \"gen/components/offline_pages/core/offline_page_model_enums_java.srcjar\",\ \"gen/net/effective_connection_type_java.srcjar\",\ \"gen/chrome/android/chrome_vr_android_java_enums_srcjar.srcjar\",\ \"gen/chrome/android/chrome_java__rjava_resources.srcjar\",\ \"gen/chrome/android/chrome_java.generated.srcjar\"\] --target-name //chrome/android:chrome_java__compile_java --header-jar obj/chrome/android/chrome_java.turbine.jar --classpath=\[\"obj/chrome/android/chrome_java.turbine.jar\"\] --classpath=@FileArg\(gen/chrome/android/chrome_java.build_config.json:deps_info:javac_full_interface_classpath\) --java-version=1.8 --bootclasspath=@FileArg\(gen/chrome/android/chrome_java.build_config.json:android:sdk_interface_jars\) --chromium-code=1 --warnings-as-errors --jar-info-exclude-globs=\[\"\*/AppHooksImpl.class\",\ \"\*/R.class\",\ \"\*/R\$\*.class\",\ \"\*/Manifest.class\",\ \"\*/Manifest\$\*.class\",\ \"\*/GEN_JNI.class\"\] --processor-arg=dagger.fastInit=enabled @gen/chrome/android/chrome_java.sources
Traceback (most recent call last):
File "../../build/android/gyp/compile_java.py", line 785, in <module>
sys.exit(main(sys.argv[1:]))
File "../../build/android/gyp/compile_java.py", line 781, in main
pass_changes=True)
File "/root/chromium/src/build/android/gyp/util/md5_check.py", line 64, in CallAndWriteDepfileIfStale
track_subpaths_allowlist=track_subpaths_allowlist)
File "/root/chromium/src/build/android/gyp/util/md5_check.py", line 155, in CallAndRecordIfStale
function(*args)
File "../../build/android/gyp/compile_java.py", line 775, in <lambda>
changes, options, javac_cmd, javac_args, java_files),
File "../../build/android/gyp/compile_java.py", line 420, in _OnStaleMd5
enable_partial_javac=True)
File "../../build/android/gyp/compile_java.py", line 549, in _RunCompiler
fail_on_output=options.warnings_as_errors)
File "/root/chromium/src/build/android/gyp/util/build_utils.py", line 271, in CheckOutput
stderr = stderr_filter(stderr)
File "../../build/android/gyp/compile_java.py", line 231, in ProcessJavacOutput
return '\n'.join(lines)
File "/root/chromium/src/build/android/gyp/javac_output_processor.py", line 83, in <genexpr>
return (self._ApplyColors(l) for l in lines)
File "/root/chromium/src/build/android/gyp/javac_output_processor.py", line 103, in _ElaborateLinesForUnknownSymbol
previous_line, line)
File "/root/chromium/src/build/android/gyp/javac_output_processor.py", line 145, in _ElaborateLineForUnknownSymbol
should_build=False)
File "../../tools/android/modularization/convenience/lookup_dep.py", line 127, in __init__
self._class_index = self._index_root()
File "../../tools/android/modularization/convenience/lookup_dep.py", line 179, in _index_root
check=True)
File "/usr/lib/python3.6/subprocess.py", line 423, in run
with Popen(*popenargs, **kwargs) as process:
TypeError: __init__() got an unexpected keyword argument 'capture_output'
ninja: build stopped: subcommand failed.
我该如何解决这个错误?
您应该手动将其添加到 chrome/android/BUILD.gn
部分 deps = [...]
在您的情况下它应该看起来像
"//third_party/android_deps:com_amplitude_android_sdk_java,"
我想为 android 构建 Chromium,我想向 Chromium 添加新的依赖项 Amplitude
。所以我将 third_party/android_deps/build.gradle 文件更改为:
dependencies {
...
compile 'com.amplitude:android-sdk:2.23.2'
...
}
然后从 third_party/android_deps/README.md 我 运行 这个命令来获取依赖项。
python third_party/android_deps/fetch_all.py --build-dir out/Default --android-deps-dir third_party/android_deps/ --ignore-vulnerabilities --ignore-licenses
执行 运行 命令后,此目录已添加到 third_party
目录。
third_party/android_deps/libs/com_amplitude_android_sdk/
third_party/android_deps/libs/com_squareup_okhttp3_okhttp/
third_party/android_deps/libs/com_squareup_okio_okio/
这些行已添加到 third_party/android_deps/BUILD.gn:
# This is generated, do not edit. Update BuildConfigGenerator.groovy instead.
java_prebuilt("com_amplitude_android_sdk_java") {
jar_path = "libs/com_amplitude_android_sdk/android-sdk-2.23.2.jar"
output_name = "com_amplitude_android_sdk"
supports_android = true
deps = [ ":com_squareup_okhttp3_okhttp_java" ]
}
# This is generated, do not edit. Update BuildConfigGenerator.groovy instead.
java_prebuilt("com_squareup_okhttp3_okhttp_java") {
jar_path = "libs/com_squareup_okhttp3_okhttp/okhttp-3.10.0.jar"
output_name = "com_squareup_okhttp3_okhttp"
supports_android = true
# To remove visibility constraint, add this dependency to
# //third_party/android_deps/build.gradle.
visibility = [
":*",
"//third_party/androidx:*",
]
deps = [ ":com_squareup_okio_okio_java" ]
}
# This is generated, do not edit. Update BuildConfigGenerator.groovy instead.
java_prebuilt("com_squareup_okio_okio_java") {
jar_path = "libs/com_squareup_okio_okio/okio-1.14.0.jar"
output_name = "com_squareup_okio_okio"
supports_android = true
# To remove visibility constraint, add this dependency to
# //third_party/android_deps/build.gradle.
visibility = [
":*",
"//third_party/androidx:*",
]
}
这些行也被添加到 third_party/android_deps/additional_readme_paths.json
[
...
"libs/com_amplitude_android_sdk",
...
"libs/com_squareup_okhttp3_okhttp",
"libs/com_squareup_okio_okio",
...
]
但我无法导入 com.amplitude.api.Amplitude
。我将此行添加到 chrome/android/java/src/org/chromium/chrome/browser/firstrun/FirstRunActivity.java:
import com.amplitude.api.Amplitude;
我收到这个错误:
FAILED: obj/chrome/android/chrome_java.javac.jar obj/chrome/android/chrome_java.javac.jar.info
python3 ../../build/android/gyp/compile_java.py --depfile=gen/chrome/android/chrome_java__compile_java.d --generated-dir=gen/chrome/android/chrome_java/generated_java --jar-path=obj/chrome/android/chrome_java.javac.jar --java-srcjars=\[\"gen/chrome/android/autofill_verification_status_generated_enum.srcjar\",\ \"gen/chrome/android/chrome_android_java_enums_srcjar.srcjar\",\ \"gen/chrome/android/chrome_android_java_google_api_keys_srcjar.srcjar\",\ \"gen/chrome/android/chrome_strict_mode_switch.srcjar\",\ \"gen/chrome/android/resource_id_javagen.srcjar\",\ \"gen/chrome/android/sync_user_settings_enums_java.srcjar\",\ \"gen/chrome/android/vr_build_config.srcjar\",\ \"gen/chrome/assist_ranker_prediction_enum_javagen.srcjar\",\ \"gen/chrome/instant_apps_reasons_enum_javagen.srcjar\",\ \"gen/chrome/offline_pages_enum_javagen.srcjar\",\ \"gen/chrome/partner_bookmarks_javagen.srcjar\",\ \"gen/chrome/quick_action_category_enum_javagen.srcjar\",\ \"gen/chrome/supervised_user_url_filter_enum_javagen.srcjar\",\ \"gen/chrome/browser/screenshot_mode_enum.srcjar\",\ \"gen/chrome/browser/sharing_dialog_type_generated_enum.srcjar\",\ \"gen/chrome/browser/sharing_send_message_result_generated_enum.srcjar\",\ \"gen/chrome/browser/survey_http_client_type_enum.srcjar\",\ \"gen/chrome/browser/notifications/scheduler/public/jni_enums.srcjar\",\ \"gen/chrome/browser/supervised_user/supervised_user_error_page/enums_srcjar.srcjar\",\ \"gen/components/autofill_assistant/browser/autofill_assistant_enums_java.srcjar\",\ \"gen/components/autofill_assistant/browser/autofill_assistant_intent_strings_java.srcjar\",\ \"gen/components/browsing_data/core/browsing_data_utils_java.srcjar\",\ \"gen/components/browsing_data/core/clear_browsing_data_tab_java.srcjar\",\ \"gen/components/data_reduction_proxy/core/browser/data_reduction_proxy_savings_cleared_enum_java.srcjar\",\ \"gen/components/dom_distiller/core/distiller_type_java.srcjar\",\ \"gen/components/ntp_tiles/ntp_tiles_enums_java.srcjar\",\ \"gen/components/offline_pages/core/offline_page_model_enums_java.srcjar\",\ \"gen/net/effective_connection_type_java.srcjar\",\ \"gen/chrome/android/chrome_vr_android_java_enums_srcjar.srcjar\",\ \"gen/chrome/android/chrome_java__rjava_resources.srcjar\",\ \"gen/chrome/android/chrome_java.generated.srcjar\"\] --target-name //chrome/android:chrome_java__compile_java --header-jar obj/chrome/android/chrome_java.turbine.jar --classpath=\[\"obj/chrome/android/chrome_java.turbine.jar\"\] --classpath=@FileArg\(gen/chrome/android/chrome_java.build_config.json:deps_info:javac_full_interface_classpath\) --java-version=1.8 --bootclasspath=@FileArg\(gen/chrome/android/chrome_java.build_config.json:android:sdk_interface_jars\) --chromium-code=1 --warnings-as-errors --jar-info-exclude-globs=\[\"\*/AppHooksImpl.class\",\ \"\*/R.class\",\ \"\*/R\$\*.class\",\ \"\*/Manifest.class\",\ \"\*/Manifest\$\*.class\",\ \"\*/GEN_JNI.class\"\] --processor-arg=dagger.fastInit=enabled @gen/chrome/android/chrome_java.sources
Traceback (most recent call last):
File "../../build/android/gyp/compile_java.py", line 785, in <module>
sys.exit(main(sys.argv[1:]))
File "../../build/android/gyp/compile_java.py", line 781, in main
pass_changes=True)
File "/root/chromium/src/build/android/gyp/util/md5_check.py", line 64, in CallAndWriteDepfileIfStale
track_subpaths_allowlist=track_subpaths_allowlist)
File "/root/chromium/src/build/android/gyp/util/md5_check.py", line 155, in CallAndRecordIfStale
function(*args)
File "../../build/android/gyp/compile_java.py", line 775, in <lambda>
changes, options, javac_cmd, javac_args, java_files),
File "../../build/android/gyp/compile_java.py", line 420, in _OnStaleMd5
enable_partial_javac=True)
File "../../build/android/gyp/compile_java.py", line 549, in _RunCompiler
fail_on_output=options.warnings_as_errors)
File "/root/chromium/src/build/android/gyp/util/build_utils.py", line 271, in CheckOutput
stderr = stderr_filter(stderr)
File "../../build/android/gyp/compile_java.py", line 231, in ProcessJavacOutput
return '\n'.join(lines)
File "/root/chromium/src/build/android/gyp/javac_output_processor.py", line 83, in <genexpr>
return (self._ApplyColors(l) for l in lines)
File "/root/chromium/src/build/android/gyp/javac_output_processor.py", line 103, in _ElaborateLinesForUnknownSymbol
previous_line, line)
File "/root/chromium/src/build/android/gyp/javac_output_processor.py", line 145, in _ElaborateLineForUnknownSymbol
should_build=False)
File "../../tools/android/modularization/convenience/lookup_dep.py", line 127, in __init__
self._class_index = self._index_root()
File "../../tools/android/modularization/convenience/lookup_dep.py", line 179, in _index_root
check=True)
File "/usr/lib/python3.6/subprocess.py", line 423, in run
with Popen(*popenargs, **kwargs) as process:
TypeError: __init__() got an unexpected keyword argument 'capture_output'
ninja: build stopped: subcommand failed.
我该如何解决这个错误?
您应该手动将其添加到 chrome/android/BUILD.gn
部分 deps = [...]
在您的情况下它应该看起来像
"//third_party/android_deps:com_amplitude_android_sdk_java,"