package { default_applicable_licenses: ["Android-Apache-2.0"], } java_defaults { name: "AconfigDemoActivityDefault", manifest: "AndroidManifest.xml", srcs: [ "src/**/*.java" ], platform_apis: true, certificate: "platform", static_libs: [ "dagger2", "jsr330", ], jni_libs: [ "libexample_cpp_lib", ], optimize: { enabled: true, proguard_compatibility: false, shrink: true, optimize: false, obfuscate: false, shrink_resources: true, }, required: ["libexample_rust_jni"], plugins: ["dagger2-compiler"] } android_app { name: "AconfigDemoActivity", defaults: ["AconfigDemoActivityDefault"], static_libs: [ "ContentLibs", ] } aconfig_declarations { name: "aconfig_demo_flags", package: "com.example.android.aconfig.demo.flags", srcs: ["aconfig_demo_flags.aconfig"], } java_aconfig_library { name: "aconfig_demo_flags_java_lib", aconfig_declarations: "aconfig_demo_flags", } filegroup { name: "ContentLibsFile", srcs: [ "lib/**/*.java", ], } java_defaults { name: "ContentLibsDefault", sdk_version: "current", srcs: [ ":ContentLibsFile", ], libs: ["jsr330"], } java_library { name: "ContentLibs", defaults: ["ContentLibsDefault"], static_libs: [ "aconfig_demo_flags_java_lib", ], } cc_aconfig_library { name: "aconfig_demo_flags_c_lib", aconfig_declarations: "aconfig_demo_flags", } cc_library { name: "libexample_cpp_lib", srcs: ["src/example_cpp_lib.cc"], double_loadable: true, cflags: [ "-Wall", "-Werror", "-Wno-unused-function", "-Wno-unused-parameter", ], header_libs: [ "jni_headers", ], shared_libs: [ "server_configurable_flags", ], static_libs: [ "aconfig_demo_flags_c_lib", ], export_include_dirs: ["src/include"], } rust_aconfig_library { name: "libaconfig_demo_flags_rust", crate_name: "aconfig_demo_flags_rust", aconfig_declarations: "aconfig_demo_flags", } rust_ffi_shared { name: "libexample_rust_jni", crate_name: "example_rust_jni", srcs: ["src/lib.rs"], rustlibs: [ "libjni", "libaconfig_demo_flags_rust", ] } // Test setup // Create test verion of the jave flag library // It needs to use the same aconfig_declarations as // the production one java_aconfig_library { name: "aconfig_demo_flags_java_lib_test", aconfig_declarations: "aconfig_demo_flags", // host_supported is set to true here for test running // one host, in tests/unittests/Android.bp host_supported: true, test: true } // Option 1 // Create a test version of the library under testing // The test version of this library shares the common // settings in a java_defaults target with the production // version library. The test version library statically // links to the test flag library, and the production // version library links to the production version flag // library. java_library { name: "ContentLibsTest1", defaults: ["ContentLibsDefault"], static_libs: [ "aconfig_demo_flags_java_lib_test", ], } // Create the test version of the android_app. This app is used // for self-instrumentation test. This app uses the test version // of the library which uses flags. // Please check tests/unittests/Android.bp:AconfigDemoUnitTests1 android_app { name: "AconfigDemoActivityTest1", defaults: ["AconfigDemoActivityDefault"], optimize: { enabled: false, }, static_libs: [ "ContentLibsTest1", ] } // Option 2 // Instead of creating two verions of the library containing flags, // it could work that create one version of the library and dynamically // link to the flag library. The flag library here just works as a stub // library for the purpose of building. The real flag library should be // statically linked in the final binary. // This library is created to demonstrate dynamically linking to flag // library java_library { name: "ContentLibs2", defaults: ["ContentLibsDefault"], sdk_version: "current", libs: [ // link the flag library for building purpose "aconfig_demo_flags_java_lib", ], } // This app is created to demonstrate the production version of the app // statically links to the production version of the flag library. android_app { name: "AconfigDemoActivity2", defaults: ["AconfigDemoActivityDefault"], static_libs: [ "ContentLibs2", "aconfig_demo_flags_java_lib", ] } // This app is created to demonstrate the test version of app uses the same // ContentLibs2 library, but links to test version of the flag library. // Please check tests/unittests/Android.bp:AconfigDemoUnitTests2 android_app { name: "AconfigDemoActivityTest2", defaults: ["AconfigDemoActivityDefault"], optimize: { enabled: false, }, static_libs: [ "ContentLibs2", "aconfig_demo_flags_java_lib", ] }