在服務器上使用 gradle 打包 android 源碼


安裝 android-tools

mkdir ~/android && cd ~/android
 
wget https://dl.google.com/android/repository/tools_r25.2.3-linux.zip
unzip tools_r25.2.3-linux.zip

配置環境變量

echo 'export ANDROID_HOME=~/android' >> ~/.bashrc
echo 'export PATH=${ANDROID_HOME}/tools/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
以編譯  https://github.com/drakeet/Ti... 為例
 
git clone https://github.com/drakeet/TimeMachine.git
cd TimeMachine
./gradlew build
漫長的等待后錯誤如下:
 
FAILURE: Build failed with an exception.
 
* What went wrong:
A problem occurred configuring project ':timemachine'.
> You have not accepted the license agreements of the following SDK components:
  [Android SDK Build-Tools 25.0.2, Android SDK Platform 25].
  Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
  Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d. android.com/r/studio-ui/export-licenses.html
 
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
 
BUILD FAILED
 
Total time: 2 mins 40.822 secs
可以看出是因為缺少 [Android SDK Build-Tools 25.0.2, Android SDK Platform 25]
 
這時執行android list sdk --all 尋找匹配的序號
 
從上圖可以看出匹配的是 3 
 
執行 android update sdk -u -a -t 3 詢問時輸入 "y" 並耐心等待
Installing Archives:
  Preparing to install archives
  Downloading Android SDK Build-tools, revision 25.0.2
  Installing Android SDK Build-tools, revision 25.0.2
    Installed Android SDK Build-tools, revision 25.0.299%)
  Done. 1 package installed.
可以看出安裝成功,再次執行 ./gradlew build 嘗試編譯, 報錯如下:
 
root@hostker:~/work/TimeMachine# ./gradlew build
Checking the license for package Android SDK Platform 25 in /root/android/licenses
Warning: License for package Android SDK Platform 25 not accepted.
 
FAILURE: Build failed with an exception.
 
* What went wrong:
A problem occurred configuring project ':timemachine'.
> You have not accepted the license agreements of the following SDK components:
  [Android SDK Platform 25].
  Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
  Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d. android.com/r/studio-ui/export-licenses.html
 
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
 
BUILD FAILED
 
Total time: 3.94 secs
可以看出是缺少 '[Android SDK Platform 25]',重復上次的過程
 
從上圖可以看出匹配的是 33 
 
執行 android update sdk -u -a -t 33 詢問時輸入 "y" 並耐心等待
Installing Archives:
  Preparing to install archives
  Downloading SDK Platform Android 7.1.1, API 25, revision 3
  Installing SDK Platform Android 7.1.1, API 25, revision 3
    Installed SDK Platform Android 7.1.1, API 25, revision 396%)
  Done. 1 package installed.
可以看出安裝成功,再次執行 ./gradlew build 嘗試編譯, 報錯如下:
 
FAILURE: Build failed with an exception.
 
* What went wrong:
A problem occurred configuring project ':timemachine'.
> You have not accepted the license agreements of the following SDK components:
  [Android SDK Platform-Tools].
  Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
  Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d. android.com/r/studio-ui/export-licenses.html
 
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
 
BUILD FAILED
 
Total time: 4.913 secs
 
android update sdk -u -a -t 2
Installing Archives:
  Preparing to install archives
  Downloading Android SDK Platform-tools, revision 25.0.3
  Installing Android SDK Platform-tools, revision 25.0.3
  Stopping ADB server failed (code -1).
    Installed Android SDK Platform-tools, revision 25.0.397%)
    Stopping ADB server succeeded.
    Starting ADB server succeeded.
  Done. 1 package installed.
FAILURE: Build failed with an exception.
 
* What went wrong:
A problem occurred configuring project ':timemachine'.
> You have not accepted the license agreements of the following SDK components:
  [Android Support Repository].
  Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
  Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d. android.com/r/studio-ui/export-licenses.html
 
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
 
BUILD FAILED
 
android update sdk -u -a -t 160
Installing Archives:
  Preparing to install archives
  Downloading Android Support Repository, revision 43
  Installing Android Support Repository, revision 43
    Installed Android Support Repository, revision 4399%)
  Done. 1 package installed.
再次嘗試編譯 ./gradlew build
 
 
FAILURE: Build failed with an exception.
 
* What went wrong:
Gradle build daemon disappeared unexpectedly (it may have been killed or may have crashed)
 
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
額... 好像 gradle 進程被殺了,可能我內存太小了吧, 下次換個大點的再試 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM