Last active
December 20, 2016 07:03
-
-
Save icyleaf/23b2c5d273df89ec0334 to your computer and use it in GitHub Desktop.
Android package based UMeng analytics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest ...> | |
<application ...> | |
<activity ...> | |
<meta-data android:name="UMENG_APPKEY" android:value="UMENG-API-KEY" /> | |
<meta-data android:name="UMENG_CHANNEL" android:value="Development" /> | |
</application> | |
<uses-permission android:name="android.permission.INTERNET" /> | |
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> | |
<uses-permission android:name="android.permission.READ_LOGS" /> | |
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> | |
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> | |
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# 基于友盟统计的 Android app 渠道打包脚本 | |
# | |
# @author icyleaf <icyleaf.cn@gmail.com> | |
# @version 0.4.3 | |
# | |
# 用法: | |
# chomd +x apkmaker.sh | |
# ./apkmaker.sh | |
# | |
# | |
# @TODO: | |
# 1. Check the source files if it all compiled | |
# 2. Generate keystore automatic | |
# 3. Compile java source files in eclipse project | |
# | |
####################################################### | |
# User Configrations | |
####################################################### | |
# | |
# Publish channels | |
# | |
CHANNELS=("91 Market" "Google Market" "GFan Market" "EOE Market" "YingYongHui Market" "Nduoa Market") | |
# | |
# Default publish channel name | |
# | |
DEFAULT_CHANNEL="Development" | |
# | |
# Android SDK path | |
# | |
ANDROID_PATH="/Users/icyleaf/Downloads/Android/android-sdk-mac_x86" | |
# | |
# Android platform version | |
# | |
ANDROID_VERSION="7" | |
# | |
# Android project path | |
# | |
PROJECT="/Users/icyleaf/src/mobile/android/leju_assistant2" | |
# | |
# project name | |
# | |
APP_NAME="koudaifangchan" | |
# | |
# project version | |
# | |
APP_VERSION="1.1.2" | |
# | |
# project output ext | |
# | |
EXT=".apk" | |
# | |
# The path let package files to store | |
# | |
STORE_PATH="/Users/icyleaf/Public/${APP_NAME}/android/${APP_VERSION}" | |
# | |
# Project classpath | |
# | |
# Sample: LIBS="libs/jar1;libs/jar2" | |
# | |
LIBS="${PROJECT}/../shared/libs/Analytics_Android_SDK_2.1.jar" | |
# | |
# sign keystore path | |
# | |
# NOTICE: If you have not a keystore, complete below config to generate it. | |
# | |
KEYSTORE="/Users/icyleaf/Documents/Works/Device/cric" | |
# | |
# KeyStore password | |
# | |
STOREPASS="cricbeijing" | |
# | |
# KeyStore key alias | |
# | |
ALIAS="cric" | |
# | |
# KeyStore key password | |
# | |
KEYPASS="cricmobile" | |
# | |
# KeyStore Informations | |
# | |
# CN: First and Last Name | |
# OU: Organizational Unit | |
# O : Organization | |
# L : City or Locality | |
# C : Country Code (XX) | |
# | |
DNAME="CN=owner, OU=Development, O=Compamy Name Inc., L=Beijing, C=CN" | |
####################################################### | |
# Script Configrations (Don't modify this section) | |
####################################################### | |
# | |
# Android platform path | |
# | |
_platform_path="${ANDROID_PATH}/platforms/android-${ANDROID_VERSION}" | |
# | |
# dex file name | |
# | |
_dexfile="classes.dex" | |
# | |
# AndroidManifest.xml file and copy file | |
# | |
_manifest="AndroidManifest.xml" | |
_manifest_copy="AndroidManifest.xml.bak" | |
####################################################### | |
# Set Global PATH | |
####################################################### | |
export PATH="$PATH:${ANDROID_PATH}/platform-tools/" | |
export PATH="$PATH:${ANDROID_PATH}/tools/" | |
####################################################### | |
# Building content | |
####################################################### | |
# Go to project path | |
cd $PROJECT | |
#echo "Generating R.java" | |
#aapt package -f -m -J "${PROJECT}/gen" -S "${PROJECT}/res" -I "${_platform_path}/android.jar" -M "${PROJECT}/AndroidManifest.xml" | |
#echo "Making class files" | |
#javac -encoding UTF-8 -target 1.5 -bootclasspath "${_platform_path}/android.jar" -d "${PROJECT}/bin" -sourcepath "${PROJECT}/src" -classpath "${PROJECT}/../shared/libs/Analytics_Android_SDK_2.1.jar" "${PROJECT}/src/com/cric/mobile/assistant/*.java" "${PROJECT}/gen/com/cric/mobile/assistant/R.java" | |
#javac -encoding UTF-8 -target 1.5 -bootclasspath "${_platform_path}/android.jar" -d bin "gen/com/cric/mobile/assistant/R.java" | |
#javac -encoding UTF-8 -target 1.5 -bootclasspath "${_platform_path}/android.jar" -classpath $LIBS -sourcepath src -d bin "com/cric/mobile/assistant/AboutusActivity.java" | |
echo "=================================================" | |
echo "Make sure the source files has been compiled!!!" | |
echo "=================================================" | |
echo "1. Clean and Backup AndroidManifest.xml file to AndroidManifest.xml.bak" | |
# clean older dex file | |
if [ -f "bin/${_dexfile}" ]; then | |
rm "bin/${_dexfile}" | |
fi | |
# clean all signed apk files | |
if [ -d $STORE_PATH ]; then | |
rm -rf $STORE_PATH | |
fi | |
# check android manifest file is not exist | |
if [ ! -f $_manifest ]; then | |
echo " => The file is not found: \"${_manifest}\" in \"${PROJECT}\"" | |
echo " => abort!!" | |
exit 1 | |
fi | |
# Restore orignal AndroidManifest.xml | |
mv $_manifest $_manifest_copy | |
# Generate a keystore if not exist | |
echo "2. Check the keystore file..." | |
if [ ! -f $KEYSTORE ]; then | |
echo "(*) Not Found keystore file" | |
echo " => Generate a key..." | |
echo " => Copy this code blew and run it, then run this script again" | |
echo | |
echo keytool -genkey -keystore $KEYSTORE -alias $ALIAS -storepass $STOREPASS -keypass $KEYPASS -dname "\"${DNAME}\"" | |
echo | |
# keytool -genkey -keystore $KEYSTORE -alias $ALIAS -storepass $STOREPASS -keypass $KEYPASS -dname "\"${DNAME}\"" | |
exit 1 | |
else | |
echo " => Found it: ${KEYSTORE}" | |
fi | |
echo "3. Beginning compile classes to dex" | |
# Convert classes to dex file | |
dx --dex --output="bin/${_dexfile}" "bin" ${LIBS} | |
echo "4. Preparing to package publish channel apk files" | |
for ((i = 0; i < ${#CHANNELS[@]}; i++ )) | |
do | |
# | |
# Publish Channel Name | |
# | |
CHANNEL=${CHANNELS[$i]} | |
# | |
# output apk file | |
# | |
SEARCH=" " | |
REPLACE="_" | |
FILE="${APP_NAME}_${CHANNELS[$i]}" | |
FILE=${FILE//$SEARCH/$REPLACE} | |
UNSIGN_FILE="${FILE}-unsign${EXT}" | |
SIGN_FILE="${FILE}-signed${EXT}" | |
# Store different publish channel name to AndroidManifest.xml | |
sed "s/${DEFAULT_CHANNEL}/${CHANNEL}/" $_manifest_copy > $_manifest | |
echo | |
echo "[${CHANNEL}]" | |
echo " => Make resource package files for ${CHANNEL}" | |
aapt package -f -M $_manifest -S res -A assets -I "${_platform_path}/android.jar" -F "bin/${FILE}" | |
echo " => Make unsign apk file" # apkbuilder will always throw a warning message | |
apkbuilder "bin/${UNSIGN_FILE}" -u -z "bin/${FILE}" -f "bin/${_dexfile}" -rf src -rj ${LIBS} | |
echo " => Sign Apk file: ${STORE_PATH}/${SIGN_FILE}" | |
if [ ! -d $STORE_PATH ]; then | |
mkdir -p $STORE_PATH | |
fi | |
jarsigner -keystore ${KEYSTORE} -storepass $STOREPASS -keypass $KEYPASS -signedjar "${STORE_PATH}/${FILE}-signed${EXT}" $"bin/${FILE}-unsign${EXT}" $ALIAS | |
# clean it | |
echo " => Clean up" | |
rm $_manifest | |
rm "bin/${FILE}" | |
rm "bin/${FILE}-unsign${EXT}" | |
done | |
# Restore orignal AndroidManifest.xml | |
mv $_manifest_copy $_manifest | |
echo "5. Everything works smooth..." | |
echo "Done!!!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 获取友盟的发布渠道 | |
* | |
* @param context | |
* @return string | |
*/ | |
public static String getPublishChannel(Context context) { | |
String result = null; | |
try { | |
ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); | |
Bundle bundle = ai.metaData; | |
result = bundle.getString("UMENG_CHANNEL"); | |
} catch (NameNotFoundException e) { | |
} | |
return result; | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AndroidManifest.xml
Android