环境
系统 :OS X EI Capitan
java :1.8.0_25
开发工具 :Android Studio
工具
Android Studio下载
http://developer.android.com/sdk/index.html
安装Android Studio
- 是否有工程已有配置文件,选择无,下一步
- Unable to access Android SDK add-on list
解决方法
sudo vi /Applications/Android\ Studio.app/Contents/bin/idea.properties
.
#
# *DO NOT* modify this file directly. If there is a value that you would like to override,
# please add it to your user specific configuration file.
#
# See http://tools.android.com/tech-docs/configuration
#
apple.laf.useScreenMenuBar=true
apple.awt.fullscreencapturealldisplays=false
apple.awt.graphics.UseQuartz=true
CVS_PASSFILE=~/.cvspass
idea.xdebug.key=-Xdebug
java.endorsed.dirs=
idea.smooth.progress=false
idea.fatal.error.notification=disabled
com.apple.mrj.application.live-resize=false
JVMVersion=1.6*
disable.android.first.run=true
点击取消,进行下一步
- Welcome Android Studio Setup Wizard,下一步
- Install Type,下一步
- Verify Settings,完成
- Downloading android-sdk-r22-macosx.zip, connect timed out,点击取消,等下解决
新建项目
- 点击Start a new Android Studio project,报错
解决方法
打开网页http://www.androiddevtools.cn/ 下载android-sdk_r24.3.4-macosx.zip (SDK Tools)
.
点击Configure-->Project Defaults-->Project Structure-->Android SDK location
- 点击Start a new Android Studio project,New Project,下一步
- Target Android Devices,
选择API 21
,下一步
- Installing Android SDK, Loading SDK information… There is nothing to install or update.
解决方法
打开网页http://www.androiddevtools.cn/ 下载 android 5.0
(SDK)
解压放到/Users/jackyshan/android-sdk-macosx/platforms目录下
打开网页http://www.androiddevtools.cn/ 下载Build-Tools 21.1.2
(Build-Tools)
解压放到/Users/jackyshan/android-sdk-macosx/build-tools目录下
打开网页http://www.androiddevtools.cn/ 下载Android SDK Extras 21.0.3
(Android SDK Extras)
解压放到/Users/jackyshan/android-sdk-macosx/extras目录下
重新点击Start a new Android Studio project,下一步,下一步
- Add an activity to Mobile,下一步
- Customize the Activity,完成
- gradle project download,等待gradle下载完
不要点击取消,有点慢
- 下载完,进入工程
- 运行报错,Error running app: Unable to obtain debug bridge
解决方法
打开网页http://www.androiddevtools.cn/ 下载 platform-tools-r22
(SDK Platform-Tools)
解压放到/Users/jackyshan/android-sdk-macosx目录下
- 运行没有问题,弹出设备选择
- 连接android手机调试,报错minSdkVersion大于当前android设备(API16)
解决方法
打开build.gradle文件,更改minSdkVersion 16
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "22.0.0"
defaultConfig {
applicationId "io.gitcafe.jackyshan.myapplication"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:21.0.3'
}
- sdk目录截图
- 我的sdk目录打包下载
如果自己怎么都弄不好,可以去百度云下载弄好的sdk
链接: http://pan.baidu.com/s/1pKustcv 密码: zhcy 密码: zhcy
打包
- 签名
点击上面build,generate signed apk,next
点击createNew,设置key Store,ok
点击next,输入密码,finish
- 配置项目框架,如图,ok
- build.gradle,生成signingConfigs,sync gradle
- 打开右侧Gradle,双击assembleRelease
- 打包完成
多渠道打包
配置build.gradle
buildTypes { release { //指定签名为release signingConfig signingConfigs.release minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } productFlavors { xiaomi {} wandoujia {} baidu {} c360 {} uc {} productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] } }
友盟配置渠道,打开AndroidManifest.xml
<meta-data android:name="UMENG_CHANNEL" android:value="${UMENG_CHANNEL_VALUE}" />
打开右侧Gradle,双击assembleRelease,打包完成(app/build/outputs/apk/)文件夹下