Mac下命令行下载android源代码并构建apk过程

前提是java 、sdk、ndk 、cmake、gradle 、gradlew都已经安装和配置好。

1、下载源码:

git clone http://git-ma.xxxx.com.cn/xxxx/xxxxx-ANDROID.git

 

2、改实际项目有用android 的small框架,框架文件夹放在master分支上。要编译的develop 分支没有这个文件夹。需要下载下

  git submodule update --init --recursive

 

3、进入android项目目录

  • ./gradlew cleanLib

 

  • ./gradlew buildLib

执行这个命令时提示:

 What went wrong:

A problem occurred configuring project ':lib.background'.

> java.io.FileNotFoundException: /Users/xxx/AndroidStudioProjects/xxxx-ANDROID/xxxx/local.properties (No such file or directory)

就手动在项目根目录下创建一个local.properties 文件。并在文件中指定sdk 和ndk位置。内容如下:

ndk.dir=/Users/xxxx/Library/Android/sdk/ndk-bundle
sdk.dir=/Users/xxxx/Library/Android/sdk

 执行结果如下:

 

  • ./gradlew cleanBundle 执行结果如下

 

 

  • ./gradlew buildBundle

 

  • 执行命令打包 ./gradlew :app:build

 

 

查看打包好的apk

 

整个放在可以放在可执行的shell脚本如下:

 

git clone http://git-xxx.xxx.xxx.cn/xxxxx/projectname-ANDROID.git;
#进入git下载的文件夹
cd projectname-ANDROID;
#获取么子模块
git submodule update --init --recursive;
#进入项目目录
cd projectname;
#新建一个local.properties 保存自己本地ndk 和sdk文件夹
touch local.properties
echo "ndk.dir=/Users/xxxxxx/workdirectory/env/android-sdk-macosx/ndk-bundle" >> local.properties
echo "sdk.dir=/Users/xxxxxx/workdirectory/env/android-sdk-macosx" >> local.properties
date;
./gradlew cleanLib -q ;
./gradlew buildLib -q ;
./gradlew cleanBundle -q;
./gradlew buildBundle -q;
# -x test -x lint 不进行单元测试
./gradlew :app:build -x test -x lint -q;

#唤醒休眠手机
adb shell input keyevent 26

#卸载apk 前提是apk已经安装
uninstall_result=`adb uninstall com.xxx.xxx`
echo "uninstall result: "$uninstall_result;
if [[ $uninstall_result == *_FAILED_* ]]
then
  echo "卸载apk不成功"
  cp usyfusfjsdf ksfsdkfsdf
else
  echo "卸载apk成功"
fi

#安装apk
install_result=`adb install ${WORKSPACE}/xxxx-ANDROID/xxxx/app/build/outputs/apk/app-release.apk`
echo "install result: "$install_result;
if [[ $install_result == *_FAILED_* ]]
then
  echo "安装apk不成功"
  cp usyfusfjsdf ksfsdkfsdf
else
  echo "安装apk成功"
fi

 

 



posted @ 2018-04-27 18:13  testway  阅读(422)  评论(0编辑  收藏  举报