Skip to content

Commit

Permalink
Use bundled proguard 5.3.3 instead of 4.7 from the SDK
Browse files Browse the repository at this point in the history
Fixes #3777

Also adds a proguard integration test so that hopefully we notice next time it breaks.

RELNOTES: Updated Android proguard to 5.3.3. It now works with android-24+.
PiperOrigin-RevId: 171162295
  • Loading branch information
aj-michael authored and aehlig committed Oct 6, 2017
1 parent 334d2f1 commit a784c8f
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ py_binary(
"//third_party/java/j2objc:embedded_tools_srcs",
"//third_party/java/jarjar:embedded_tools_srcs",
"//third_party/java/jdk/langtools:test-srcs",
"//third_party/java/proguard:embedded_tools",
"//third_party/py/concurrent:srcs",
"//third_party/py/gflags:srcs",
"//third_party/py/six:srcs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ public void setupMockClient(MockToolsConfig config) throws IOException {
config.create(
"/bazel_tools_workspace/tools/android/emulator/BUILD",
Iterables.toArray(createToolsAndroidEmulatorContents(), String.class));
// Bundled Proguard used by android_sdk_repository
config.create(
"/bazel_tools_workspace/third_party/java/proguard/BUILD",
"exports_files(['proguard'])");

config.create(
"/bazel_tools_workspace/tools/genrule/BUILD", "exports_files(['genrule-setup.sh'])");
Expand Down
52 changes: 52 additions & 0 deletions src/test/shell/bazel/android/android_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,58 @@ function test_allow_custom_manifest_name() {
"Failed to build android_binary with custom Android manifest file name"
}

function test_proguard() {
create_new_workspace
setup_android_sdk_support
mkdir -p java/com/bin
cat > java/com/bin/BUILD <<EOF
android_binary(
name = 'bin',
srcs = ['Bin.java', 'NotUsed.java'],
manifest = 'AndroidManifest.xml',
proguard_specs = ['proguard.config'],
deps = [':lib'],
)
android_library(
name = 'lib',
srcs = ['Lib.java'],
)
EOF
cat > java/com/bin/AndroidManifest.xml <<EOF
<manifest package='com.bin' />
EOF
cat > java/com/bin/Bin.java <<EOF
package com.bin;
public class Bin {
public Lib getLib() {
return new Lib();
}
}
EOF
cat > java/com/bin/NotUsed.java <<EOF
package com.bin;
public class NotUsed {}
EOF
cat > java/com/bin/Lib.java <<EOF
package com.bin;
public class Lib {}
EOF
cat > java/com/bin/proguard.config <<EOF
-keep public class com.bin.Bin {
public *;
}
EOF
assert_build //java/com/bin
output_classes=$(zipinfo -1 bazel-bin/java/com/bin/bin_proguard.jar)
assert_equals 3 $(wc -w <<< $output_classes)
assert_one_of $output_classes "META-INF/MANIFEST.MF"
assert_one_of $output_classes "com/bin/Bin.class"
# Not kept by proguard
assert_not_one_of $output_classes "com/bin/Unused.class"
# This is renamed by proguard to something else
assert_not_one_of $output_classes "com/bin/Lib.class"
}

if [[ ! -d "${TEST_SRCDIR}/androidsdk" ]]; then
echo "Not running Android tests due to lack of an Android SDK."
exit 0
Expand Down
18 changes: 18 additions & 0 deletions src/test/shell/unittest.bash
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,24 @@ function assert_one_of() {
return 1
}

# Usage: assert_not_one_of <expected_list>... <actual>
# Asserts that actual is not one of the items in expected_list
# Example: assert_not_one_of ( "foo", "bar", "baz" ) actualval
function assert_not_one_of() {
local args=("$@")
local last_arg_index=$((${#args[@]} - 1))
local actual=${args[last_arg_index]}
unset args[last_arg_index]
for expected_item in "${args[@]}"; do
if [ "$expected_item" = "$actual" ]; then
fail "'${args[@]}' contains '$actual'"
return 1
fi
done;

return 0
}

# Usage: assert_equals <expected> <actual>
# Asserts [ expected = actual ].
function assert_equals() {
Expand Down
13 changes: 1 addition & 12 deletions tools/android/android_sdk_repository_template.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def create_android_sdk_rules(
native.android_sdk(
name = "sdk-%d" % api_level,
build_tools_version = build_tools_version,
proguard = ":proguard_binary",
proguard = "@bazel_tools//third_party/java/proguard",
aapt = select({
":windows": "build-tools/%s/aapt.exe" % build_tools_directory,
":windows_msvc": "build-tools/%s/aapt.exe" % build_tools_directory,
Expand Down Expand Up @@ -141,17 +141,6 @@ def create_android_sdk_rules(
actual = ":sdk-%d" % default_api_level,
)

native.java_import(
name = "proguard_import",
jars = ["tools/proguard/lib/proguard.jar"]
)

native.java_binary(
name = "proguard_binary",
main_class = "proguard.ProGuard",
runtime_deps = [":proguard_import"]
)

native.java_binary(
name = "apksigner",
main_class = "com.android.apksigner.ApkSignerTool",
Expand Down

0 comments on commit a784c8f

Please sign in to comment.