Skip to content

Commit

Permalink
Set default primary dex patterns for android_instrumentation_apk
Browse files Browse the repository at this point in the history
Summary:
Buck1 allows building android_instrumentation_apk with enabled multidex without specifying `primary_dex_patterns`, but fails with
```
Exception in thread "main" java.lang.IllegalStateException: No primary dex classes were specified!
Please add primary_dex_patterns to ensure that at least one class exists in the primary dex.
```
This diff introduce default value for primary_dex_patterns and adds same patterns as regular apk.
Now it is possible to skip `primary_dex_patterns`.
```
fb_native.android_instrumentation_apk(
    name = "test_apk_multidex_no_primary_dex_patterns",
    aapt_mode = "aapt2",
    apk = ":apk_under_test",
    labels = ["buck2-only"],
    manifest_skeleton = "TestApkAndroidManifest.xml",
    use_split_dex = True,
    deps = [
        "fbsource//fbandroid/buck2/tests/good/apk:android_prebuilt_aar_with_native_libs1",
        "fbsource//fbandroid/buck2/tests/good/apk:cxx_library",
        ":resources",
        ":resources_with_different_package",
        ":split_apk_test_class",
        ":test_activity",
    ],
)
```

This diff based on suggestion in D52804766.

Reviewed By: IanChilds

Differential Revision: D52838715

fbshipit-source-id: e6bd9866cceb589a018b3d2b51a1921c07544510
  • Loading branch information
Ivan Balaksha authored and facebook-github-bot committed Jan 17, 2024
1 parent 455b3b3 commit 5b21491
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions prelude/native.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,17 @@ def _android_binary_macro_stub(

def _android_instrumentation_apk_macro_stub(
cpu_filters = None,
primary_dex_patterns = [],
**kwargs):
primary_dex_patterns = primary_dex_patterns + [
"/R^",
"/R$",
# Pin this to the primary for apps with no primary dex classes.
"^com/facebook/buck_generated/AppWithoutResourcesStub^",
]
__rules__["android_instrumentation_apk"](
cpu_filters = _get_valid_cpu_filters(cpu_filters),
primary_dex_patterns = primary_dex_patterns,
**kwargs
)

Expand Down

0 comments on commit 5b21491

Please sign in to comment.