From 5b21491ed603d917af14d20b9cc85179b833fbc5 Mon Sep 17 00:00:00 2001 From: Ivan Balaksha Date: Wed, 17 Jan 2024 10:26:47 -0800 Subject: [PATCH] Set default primary dex patterns for android_instrumentation_apk 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 --- prelude/native.bzl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/prelude/native.bzl b/prelude/native.bzl index 9c37d87c..1bbadd2a 100644 --- a/prelude/native.bzl +++ b/prelude/native.bzl @@ -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 )