Skip to content

Instantly share code, notes, and snippets.

@jakeouellette
Last active April 3, 2017 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakeouellette/608d934efaaf50b3cb15886e66009664 to your computer and use it in GitHub Desktop.
Save jakeouellette/608d934efaaf50b3cb15886e66009664 to your computer and use it in GitHub Desktop.
Example shell script to pull Crashlytics Gradle plugin and call it
#!/bin/sh
# Copyright 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# The following is an example of calling our Android Gradle Fabric plugin via the command line shell
file=io-fabric-tools-gradle.jar # Define the plugin name so that we can download & execute it
# This is optional, but I wasn't sure if this would only be used by buck folks :)
get_fabric_tool () {
path=http://maven.fabric.io/public/io/fabric/tools
version=$(curl -Ls $path/maven-metadata.xml | grep release | sed "s/.*<release>\([^<]*\)<\/release>.*/\1/")
if [ -f $file ]; then # Download if the file doesn't exist yet,
echo using cached fabric tool, "$file"
else
jar=io-fabric-tools-gradle-"$version".jar
echo downloading latest fabric tool, "$path/$version/$jar"
wget -q -N "$path/$version/$jar"
mv io-fabric-tools-gradle-"$version".jar "$file" # Rename so it has a predictable name
fi
}
run_task () {
args="$1-projectPath $project_path \n"
args="$args-androidManifest $manifest_path \n"
args="$args-androidBaseManifest $base_manifest_path \n"
args="$args-androidRes $res_path \n"
args="$args-androidAssets $assets_path \n"
# Todo: only do this if there is a build id
args="$args-buildId $build_id \n"
args="$args-targetResValueDir $target_res_values_dir \n"
# You might replace consider replacing this with 'buck', not super important
args="$args-version 0.0 \n"
args="$args-tool shell \n"
if [ ! "$properties" = '' ] ; then
args="$args-properties $properties \n"
fi
run_tool "$args"
}
run_ndk_task () {
args="$args-enableNDK true \n"
args="$args-androidNdkOut NDK_OUT_PROPERTY_NEEDED \n"
args="$args-androidNdkLibsOut NDK_LIBS_OUT_PROPERTY_NEEDED \n"
args="$args-cSymGen C_SYM_GEN_DIR_PROPERTY_NEEDED \n"
args="$args-cSymCache C_SYM_CACHE_DIR_PROPERTY_NEEDED \n"
args="$args-cSymArchive C_SYM_ARCHIVE_DIR_PROPERTY_NEEDED \n"
run_task "$args"
}
run_tool () {
echo "$@"
echo "$@" | tr -d "\n" | xargs java -cp $file com.crashlytics.tools.android.DeveloperTools gradleMain
}
generate_resources () {
args="-buildEvent \n"
args="$args-injectableManifest \n"
# This task doesn't always need to be run, we only *really* need a new build id when you're doing a release build.
target_res_file="$target_res_values_dir"/values/com_crashlytics_export_strings.xml
if [ "$preserve_build_id" = true ] && [ -f "$target_res_file" ] ; then
args="$args-preserveBuildId"
fi
run_task "-generateResourceFile \n$args"
}
store_deobs () {
args="-obfuscator proguard-via-shell \n"
args="$args-obVer 0.0 \n"
args="$args-obfuscating \n" # TODO: Remove this line if you are not obfuscating
run_task "-storeDeobs $mapping_file \n$args"
}
upload_deobs () {
# "There's an optional parameter, -requireUploadSuccess, that makes the build fail if the upload fails, otherwise mapping files are cached.
run_task "-uploadDeobs \n"
}
pre_build () {
generate_resources
store_deobs
}
post_build () {
upload_deobs
}
ndk_build () {
run_ndk_task "-cacheCSyms \n"
run_ndk_task "-generateCSyms \n"
# Optional arg you can add to csym upload... especially if running on CI, you can require mapping.txt uploads to succeed:
run_ndk_task "-uploadCSyms \n" #" -requireUploadSuccess \n"
}
preserve_build_id=false
mapping_file=PROPERTY_NEEDED
project_path=.
manifest_path=PROPERTY_NEEDED
base_manifest_path=PROPERTY_NEEDED
res_path=PROPERTY_NEEDED
assets_path=PROPERTY_NEEDED
target_res_values_dir=PROPERTY_NEEDED
properties=''
# IMPORTANT: This build_id must match between pre_build and post_build
build_id=$(uuidgen)
get_fabric_tool
pre_build
post_build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment