Trouble adding pre-build JAR into Android build

429 views
Skip to first unread message

Dean Wedel

unread,
Jan 31, 2025, 10:29:25 AM1/31/25
to Chromium-dev
I'm trying to add a pre-built JAR into an Android build (dev environment is Ubuntu).

Here are my steps and then where the build fails at the end. It appears like it doesn't like the "library name" but I don't understand how to fix this. Does anyone know what I need to change?

Integrate pre-built "Sentry" JAR into Android build ~ starting with a working build:
1. $ mkdir third_party/sentry
2. $ cd third_party/sentry
3. $ wget https://repo1.maven.org/maven2/io/sentry/sentry-android/8.1.0/sentry-android-8.1.0.aar
4. $ unzip sentry-android-8.1.0.aar
5. Create "BUILD.gn" in that directory to be:
     import("//build/config/android/rules.gni")
     java_prebuilt("sentry-android") {
         jar_path = "//third_party/sentry/classes.jar"
         deps = [
             # Add dependencies if any (other Java libraries)
         ]
     }
6. $ cd ../..
7. Edit "chrome/android/BUILD.gn" to include:
   IN THIS SECTION:
   -------------------------------------------------------
      android_resources("chrome_app_java_resources") {
        sources = chrome_java_resources
        sources += [ "//chrome/android/java/res_app/layout/main.xml" ]
        deps = [

   ADD THIS ENTRY:
   -------------------------------------------------------
        "//third_party/sentry:sentry-android",
8. Build with: $ autoninja -C out/Default chrome_public_apk -j 10
   RESULTS IN FAILURE:
   -------------------------------------------------------
   ninja: Entering directory `out/Default'
[0/1] Regenerating ninja files
ERROR at //build/config/android/internal_rules.gni:139:9: Assertion failed.
        assert(false, "Invalid java library target name: $_target_label")
        ^-----
Invalid java library target name: //third_party/sentry:sentry-android
See //build/config/android/internal_rules.gni:3746:5: whence it was called.
    write_build_config(_build_config_target_name) {
    ^----------------------------------------------
See //build/config/android/rules.gni:1419:5: whence it was called.
    java_library_impl(target_name) {
    ^-------------------------------
See //third_party/sentry/BUILD.gn:3:1: whence it was called.
java_prebuilt("sentry-android") {
^--------------------------------
See //chrome/android/BUILD.gn:273:7: which caused the file to be included.
      "//third_party/sentry:sentry-android",
      ^------------------------------------
FAILED: build.ninja.stamp
../../buildtools/linux64/gn --root=../.. -q --regeneration gen .
ninja: error: rebuilding 'build.ninja': subcommand failed

Torne (Richard Coles)

unread,
Jan 31, 2025, 10:47:24 AM1/31/25
to dean....@gmail.com, Chromium-dev
You need to change the actual build target name you are declaring in `BUILD.gn` to something that ends in _java.

i.e. change "sentry-android" to "sentry_android_java" or similar. Our build setup in gn for java targets expects them all to follow this naming convention. It's nothing to do with what's actually in the jar.

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/6117e137-73af-4aec-bc9d-a0fd957f8c96n%40chromium.org.

Dean Wedel

unread,
Jan 31, 2025, 11:05:48 AM1/31/25
to Chromium-dev, Torne (Richard Coles), Chromium-dev, dean....@gmail.com
Thanks for that input! I updated both BUILD.gn files to use "sentry_android_java" instead. Now the build likes it and is busy working through 103539 files . . . .

Dean Wedel

unread,
Jan 31, 2025, 1:00:38 PM1/31/25
to Chromium-dev, Dean Wedel, Torne (Richard Coles), Chromium-dev
Thanks again for your help ~ that got me going for awhile.

But could you give me some guidance on another build crash?
One other file that I had modified with this Sentry integration is in "chrome/android/java/src/org/chromium/chrome/browser/ChromeApplicationImpl.java" where I had added the following 2 "imports"
import io.sentry.Sentry;
import io.sentry.android.AndroidSentryClient;

And then down in the "public void onCreate()" function I've added the Sentry initializer:
        String dsn = "***********";
        AndroidSentryClient sentry = new AndroidSentryClient(context, dsn);

But the make crashes with:
[36225/103539] ACTION //chrome/android:chrome_java__compile_java(//build/toolchain/android:android_clang_arm64)
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/chrome_android_java_enums_srcjar.srcjar\",\ \"gen/chrome/android/chrome_strict_mode_switch.srcjar\",\ \"gen/chrome/android/resource_id_javagen.srcjar\",\ \"gen/chrome/offline_pages_enum_javagen.srcjar\",\ \"gen/chrome/partner_bookmarks_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/notifications/scheduler/public/jni_enums.srcjar\",\ \"gen/components/contextual_search/core/browser/quick_action_category_enum_javagen.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/components/supervised_user/core/browser/supervised_user_utils_enum_javagen.srcjar\",\ \"gen/chrome/android/chrome_jni_headers.srcjar\",\ \"gen/chrome/android/chrome_java__assetres.srcjar\",\ \"gen/chrome/android/chrome_java.generated.srcjar\"\] --target-name //chrome/android:chrome_java__compile_java --classpath=@FileArg\(gen/chrome/android/chrome_java.build_config.json:android:sdk_interface_jars\) --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\) --chromium-code=1 --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
No suggested deps for io.sentry.Sentry
No suggested deps for io.sentry.android.AndroidSentryClient
../../chrome/android/java/src/org/chromium/chrome/browser/ChromeApplicationImpl.java:38: error: package io.sentry does not exist
import io.sentry.Sentry;
                ^
../../chrome/android/java/src/org/chromium/chrome/browser/ChromeApplicationImpl.java:39: error: package io.sentry.android does not exist
import io.sentry.android.AndroidSentryClient;
                        ^
../../chrome/android/java/src/org/chromium/chrome/browser/ChromeApplicationImpl.java:61: error: cannot find symbol
        AndroidSentryClient sentry = new AndroidSentryClient(context, dsn);
        ^
  symbol:   class AndroidSentryClient
  location: class ChromeApplicationImpl
../../chrome/android/java/src/org/chromium/chrome/browser/ChromeApplicationImpl.java:61: error: cannot find symbol
        AndroidSentryClient sentry = new AndroidSentryClient(context, dsn);
                                         ^
  symbol:   class AndroidSentryClient
  location: class ChromeApplicationImpl
../../chrome/android/java/src/org/chromium/chrome/browser/ChromeApplicationImpl.java:61: error: cannot find symbol
        AndroidSentryClient sentry = new AndroidSentryClient(context, dsn);
                                                             ^
  symbol:   variable context
  location: class ChromeApplicationImpl
../../chrome/android/java/src/org/chromium/chrome/browser/ChromeApplicationImpl.java:62: error: cannot find symbol
        Sentry.init(sentry);
        ^
  symbol:   variable Sentry
  location: class ChromeApplicationImpl
../../chrome/android/java/src/org/chromium/chrome/browser/ChromeApplicationImpl.java:69: error: cannot find symbol
            Sentry.captureException(e);
            ^
  symbol:   variable Sentry
  location: class ChromeApplicationImpl
7 errors
[36234/103539] ACTION //chrome/browser/commerce/merchant_viewer/android:java__dex(//build/toolchain/android:android_clang_arm64)
ninja: build stopped: subcommand failed.


Why can't that library be imported? What am I doing wrong?

Torne (Richard Coles)

unread,
Jan 31, 2025, 1:33:44 PM1/31/25
to Dean Wedel, Chromium-dev
Did you add a dependency from the target that contains ChromeApplicationImpl to the one you added with the jar in it?

Java code in Chromium is built only against the specific java dependencies that are declared in BUILD.gn, not everything.

Dean Wedel

unread,
Jan 31, 2025, 1:50:43 PM1/31/25
to Chromium-dev, Torne (Richard Coles), Chromium-dev, Dean Wedel
Probably not. . .
It looks like in the "chrome/android/BUILD.gn" file I added it to the "chrome_app_java_resources" section.
> android_resources("chrome_app_java_resources")

How do I determine which section that I need to update that ?? to include the dependency? According to this "fail" line:
> FAILED: obj/chrome/android/chrome_java.javac.jar obj/chrome/android/chrome_java.javac.jar.info
Does that mean it's in section "chrome_java" in the "chrome/android/BUILD.gn" file?

I'm not at all sure how to determine which section that I need to add it to?

Torne (Richard Coles)

unread,
Jan 31, 2025, 2:06:04 PM1/31/25
to Dean Wedel, Chromium-dev
On Fri, 31 Jan 2025 at 13:50, Dean Wedel <dean....@gmail.com> wrote:
Probably not. . .
It looks like in the "chrome/android/BUILD.gn" file I added it to the "chrome_app_java_resources" section.
> android_resources("chrome_app_java_resources")

How do I determine which section that I need to update that ?? to include the dependency? According to this "fail" line:
> FAILED: obj/chrome/android/chrome_java.javac.jar obj/chrome/android/chrome_java.javac.jar.info
Does that mean it's in section "chrome_java" in the "chrome/android/BUILD.gn" file?

Yes.
 
I'm not at all sure how to determine which section that I need to add it to?

If you already got a build error it's generally apparent from the name of the thing it was trying to build when it failed, as you did above. You can also just look at where the specific Java source file in question is being included in the build, though in this case it's slightly indirect. You're adding the imports to ChromeApplicationImpl.java, which is included in the build not directly inside a target but through being listed in the `chrome_java_sources` variable defined in chrome/android/chrome_java_sources.gni, and that variable is then used by //chrome/android:chrome_java.

The Chromium build system is designed around (almost) everything being explicitly specified in the build configuration: we list the names of all the individual source files to be compiled into each target and list which targets have dependencies on which other targets. This is pretty different to how most build systems for Java code work, so may take a little getting used to, but it means that things work broadly the same way for both Java and C++ code, and avoids a few otherwise-common problems with local/incremental builds when files are created/deleted and the build is using wildcards/recursive directory searching to decide what to include.

Dean Wedel

unread,
Jan 31, 2025, 3:48:24 PM1/31/25
to Chromium-dev, Torne (Richard Coles), Chromium-dev, Dean Wedel
Thanks again! I appreciate your wisdom and guidance here.

After doing that modification I get a different error saying that the Sentry isn't compatable:
Traceback (most recent call last):
  File "../../build/android/gyp/write_build_config.py", line 2191, in <module>
    sys.exit(main(sys.argv[1:]))
  File "../../build/android/gyp/write_build_config.py", line 1513, in main
    raise Exception('Not all deps support the Android platform:\n' +
Exception: Not all deps support the Android platform:
* //third_party/sentry:sentry_android_java

Is there any way to get around that or am I just out of options?

Torne (Richard Coles)

unread,
Jan 31, 2025, 3:56:30 PM1/31/25
to Dean Wedel, Chromium-dev
See https://source.chromium.org/chromium/chromium/src/+/main:build/android/docs/java_toolchain.md for the target types; it looks like you're defining the prebuilt jar with `java_prebuilt` but you would need to use `android_java_prebuilt` here.

Dean Wedel

unread,
Mar 5, 2025, 8:14:05 AM3/5/25
to Chromium-dev, Torne (Richard Coles), Chromium-dev, Dean Wedel
I'm back on this project with adding a pre-built "Senry" JAR to the Android/Chromium project. Using your advice above it goes pretty good until late in the build I hit this error. I don't understand what it's reporting. What do I need to correct?
> [104987/104991] ACTION //chrome/android:chrome_public_apk__final_dex(//build/toolchain/android:android_clang_arm64)
FAILED: obj/chrome/android/chrome_public_apk/chrome_public_apk.r8dex.jar apks/ChromePublic.apk.mapping
python3 ../../build/android/gyp/proguard.py --min-api=26 --mapping-output apks/ChromePublic.apk.mapping --classpath @FileArg\(gen/chrome/android/chrome_public_apk.build_config.json:deps_info:proguard_classpath_jars\) --classpath @FileArg\(gen/chrome/android/chrome_public_apk.build_config.json:android:sdk_jars\) --r8-path ../../third_party/r8/lib/r8.jar --custom-r8-path ../../third_party/r8/custom_r8.jar --package-name=@FileArg\(gen/chrome/android/chrome_public_apk.build_config.json:deps_info:package_name\) --source-file chromium-ChromePublic.apk-default-@FileArg\(gen/chrome/android/chrome_public_apk.build_config.json:deps_info:version_code\) --proguard-configs=@FileArg\(gen/chrome/android/chrome_public_apk.build_config.json:deps_info:proguard_all_configs\) --enable-obfuscation --proguard-configs=\[\"../../build/android/dcheck_is_off.flags\",\ \"../../third_party/jni_zero/checkdiscard_proguard.flags\"\] --input-art-profile=../../chrome/android/baseline_profiles/profile.txt --input-paths=@FileArg\(gen/chrome/android/chrome_public_apk.build_config.json:deps_info:device_classpath\) --output-path obj/chrome/android/chrome_public_apk/chrome_public_apk.r8dex.jar --depfile gen/chrome/android/chrome_public_apk__final_dex.d
Error in ../../third_party/kotlin_stdlib/kotlin-stdlib.jar:org/intellij/lang/annotations/JdkConstants$AdjustableOrientation.class:
Type org.intellij.lang.annotations.JdkConstants$AdjustableOrientation is defined multiple times: ../../third_party/kotlin_stdlib/kotlin-stdlib.jar:org/intellij/lang/annotations/JdkConstants$AdjustableOrientation.class, obj/third_party/sentry/org_jetbrains_annotations_java.processed.jar:org/intellij/lang/annotations/JdkConstants$AdjustableOrientation.class
Exception in thread "main" com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: ../../third_party/kotlin_stdlib/kotlin-stdlib.jar:org/intellij/lang/annotations/JdkConstants$AdjustableOrientation.class
at Version.fakeStackEntry(Version_main.java:0)
at com.android.tools.r8.InternalCompilationFailedExceptionUtils.create(InternalCompilationFailedExceptionUtils.java:29)
at com.android.tools.r8.utils.ExceptionUtils.failWithFakeEntry(ExceptionUtils.java:145)
at com.android.tools.r8.utils.ExceptionUtils.failCompilation(ExceptionUtils.java:89)
at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:83)
at com.android.tools.r8.utils.ExceptionUtils.withR8CompilationHandler(ExceptionUtils.java:69)
at com.android.tools.r8.R8.runForTesting(R8.java:238)
at com.android.tools.r8.R8.run(R8.java:194)
at org.chromium.build.CustomR8.main(CustomR8.java:43)
Caused by: com.android.tools.r8.utils.AbortException: Type org.intellij.lang.annotations.JdkConstants$AdjustableOrientation is defined multiple times: ../../third_party/kotlin_stdlib/kotlin-stdlib.jar:org/intellij/lang/annotations/JdkConstants$AdjustableOrientation.class, obj/third_party/sentry/org_jetbrains_annotations_java.processed.jar:org/intellij/lang/annotations/JdkConstants$AdjustableOrientation.class
at com.android.tools.r8.utils.Reporter.handleDiagnostic(Reporter.java:81)
at com.android.tools.r8.utils.Reporter.fatalError(Reporter.java:129)
at com.android.tools.r8.utils.ProgramClassCollection.reportDuplicateTypes(ProgramClassCollection.java:97)
at com.android.tools.r8.utils.ProgramClassCollection.lambda$wrappedConflictResolver$1(ProgramClassCollection.java:91)
at com.android.tools.r8.utils.ProgramClassCollection.lambda$create$0(ProgramClassCollection.java:32)
at java.base/java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:2056)
at com.android.tools.r8.utils.ProgramClassCollection.create(ProgramClassCollection.java:31)
at com.android.tools.r8.graph.LazyLoadedDexApplication$Builder.build(LazyLoadedDexApplication.java:314)
at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:157)
at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:111)
at com.android.tools.r8.dex.ApplicationReader.read(ApplicationReader.java:99)
at com.android.tools.r8.R8.run(R8.java:289)
at com.android.tools.r8.R8.run(R8.java:251)
at com.android.tools.r8.R8.lambda$runForTesting$1(R8.java:242)
at com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:80)
... 4 more

ninja: build stopped: subcommand failed.


Torne (Richard Coles)

unread,
Mar 5, 2025, 10:31:38 AM3/5/25
to Dean Wedel, Chromium-dev
Type org.intellij.lang.annotations.JdkConstants$AdjustableOrientation is defined multiple times: ../../third_party/kotlin_stdlib/kotlin-stdlib.jar:org/intellij/lang/annotations/JdkConstants$AdjustableOrientation.class, obj/third_party/sentry/org_jetbrains_annotations_java.processed.jar:org/intellij/lang/annotations/JdkConstants$AdjustableOrientation.class

The jar you are adding contains classes that already exist in other parts of the Chromium java build, which isn't allowed - we already have those annotation types defined by the kotlin stdlib. You would need to filter them out when including your jar with `jar_excluded_patterns` probably?

Dean Wedel

unread,
Apr 15, 2025, 1:14:29 PM4/15/25
to Chromium-dev, Torne (Richard Coles), Chromium-dev, Dean Wedel
I'm revisiting this project of adding a pre-built JAR to the Chromium/Android build.

Here are the files that I've modified so far:
> 1. created directory third_party/sentry-android
>     ADDED:
>                  BUILD.gn (android_java_prebuilt("sentry_android_java") { jar_path = "//third_party/sentry-android/sentry-6.34.0.jar" deps = [] } )
>                  LICENSE
>                  sentry-6.34.0.jar (downloaded from the sentry-android repo)
> 2. Edited: chrome/android/BUILD.gn
>     MODIFIED/ADDED: chrome_deps = [ ":delegate_public_impl_java", "//third_party/sentry-android:sentry_android_java" ]
> 3. Modified chrome/android/java/src/org/chromium/chrome/browser/ChromeApplicationImpl.java
>     ADDED: import io.sentrySentry;
        

When I build it appears to not be including that JAR into the build ~ what am I missing? What do I change?
[36615/105248] ACTION //chrome/android:chrome_java__compile_java(//build/toolchain/android:android_clang_arm64)

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/chrome_android_java_enums_srcjar.srcjar\",\ \"gen/chrome/android/chrome_strict_mode_switch.srcjar\",\ \"gen/chrome/android/resource_id_javagen.srcjar\",\ \"gen/chrome/offline_pages_enum_javagen.srcjar\",\ \"gen/chrome/partner_bookmarks_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/notifications/scheduler/public/jni_enums.srcjar\",\ \"gen/components/contextual_search/core/browser/quick_action_category_enum_javagen.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/components/supervised_user/core/browser/supervised_user_utils_enum_javagen.srcjar\",\ \"gen/chrome/android/chrome_jni_headers.srcjar\",\ \"gen/chrome/android/chrome_java__assetres.srcjar\",\ \"gen/chrome/android/chrome_java.generated.srcjar\"\] --target-name //chrome/android:chrome_java__compile_java --classpath=@FileArg\(gen/chrome/android/chrome_java.build_config.json:android:sdk_interface_jars\) --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\) --chromium-code=1 --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
../../chrome/android/java/src/org/chromium/chrome/browser/ChromeApplicationImpl.java:12: error: package io.sentry does not exist
import io.sentry.Sentry;


Where am I missing the include or dependency? I thought adding the reference in "chrome/android/BUILD.gn" would address this?

Dean Wedel

unread,
Apr 15, 2025, 2:13:10 PM4/15/25
to Chromium-dev, Dean Wedel, Torne (Richard Coles), Chromium-dev
And as a verification follow-up I verified that the actual JAR seems to report correctly:
> $ jar tvf third_party/sentry-android/sentry-6.34.0.jar
--- lots of info
> 24682 Mon Nov 20 13:06:58 MST 2023 io/sentry/Sentry.class
--- lots more info

Sam Maier

unread,
Apr 15, 2025, 2:27:57 PM4/15/25
to dean....@gmail.com, Chromium-dev, Torne (Richard Coles)

Dean Wedel

unread,
Apr 15, 2025, 4:56:52 PM4/15/25
to Chromium-dev, Sam Maier, Chromium-dev, Torne (Richard Coles), dean....@gmail.com
Yes!
That was it. Thank you for sharing that knowledge.
Reply all
Reply to author
Forward
0 new messages