搭建android app,新入的Mac很不顺手,在配环境的时候走了很多弯路,查询了很多网站(主要在stackoverflow上),得到了解决,记录如下/
Mac里面没有配置android环境。所以配环境吧
1)下载android sdk,下载链接https://developer.android.com/studio/index.html
2)解压得到同名文件夹一枚,把这个文件夹放到你想放的地方去,记住路径,并且路径中不能有中文字符存在。本文路径以我本人为例,放到了/developer里面,具体路径就为/developer/android-sdk-macosx/
3) 进入相关的目录,找到tools文件夹,点击android,出现安装界面,记得一定要同意相关的用户协议(需要翻墙),安装完相应的platform-tools和build-tools之后可以发现在/developer/android-sdk-macosx/ 目录下多了两个这两个文件夹
4) 配置环境变量
$ vim .bash_profile
export ANDROID_HOME=/Users/我的名字/developer/android-sdk-macosx
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
这里出错的地方就是path里面要有到tools和到platform-tools的路径,不然之后就报错了。。
配置完成之后可以检查是否正确,命令行输入
echo $PATH
echo $ANDROID_HOME
可以正确显示。
3环境配置成功,继续回到weex的项目目录下,weexpack run android,出现了新的错误
Downloading http://services.gradle.org/distributions/gradle-2.14.1-all.zip Exception in thread "main" Java.lang.RuntimeException: java.NET.UnknownHostException: downloads.gradle.org at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:78) at org.gradle.wrapper.Install.createDist(Install.java:47) at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129) at org.gradle.wrapper.Grad
说下载gradle的时候出错,参考网上说法,采用先下载到本地再修改下载链接的方法解决错误
1) 通过http://services.gradle.org/distributions/gradle-2.14.1-all.zip把gradle.zip下载的本地
2) 复制gradle-2.14.1-all.zip到myApp/platforms/android/gradle目录中
3) 把源文件中的disributionUrl修改为 var distributionUrl = '../gradle-2.2.1-all.zip';
这里的问题就是找到disributionUrl的定义位置,小白的在myApp/platforms/android/cordova/lib/builders文件夹里GradleBuilder.js里,
var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'http//://services.gradle.org/distributions/gradle-2.14.1-all.zip';
问题解决。
4继续weexpack run android,新的错误出现了
A problem occurred configuring root project 'android'. You have not accepted the license agreements of the following SDK components: [Android SDK Platform 24].
=> Building app ...
File /Users/zhimaiMAC/.android/repositories.cfg could not be loaded.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> You have not accepted the license agreements of the following SDK components:
[Android SDK Platform 23, Android SDK Build-Tools 23.0.2].
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
原因:Cordova创建成功后会建立licenses文件,手动建立即可
命令行输入以下命令
mkdir "$ANDROID_HOME/licenses"
echo -e "/n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
这次终于好了,运行成功!