Ubuntu1804搭建Android开发环境

  • 下载安装
  • 配置应用图标和gradle
  • 出现的问题

安装

下载链接: Linux

配置

应用图标

在路径: ~/.local/share/applications下:

1
2
3
4
5
6
7
8
[Desktop Entry]
Name=Android Studio
Comment=Android
Icon=/home/zhibo/Tools/android-studio/bin/studio.png
Exec=/home/zhibo/Tools/android-studio/bin/studio.sh
Terminal=false
Type=Application
Categories=Application;Development;

gradle工具

主要是镜像问题,不然同步很慢(PS:网络原因).

方法一(单项目)

修改此项目根目录下的文件 build.gradle

1
2
3
4
5
6
7
8
9
10
11
buildscript {
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}
}

allprojects {
repositories {
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
}
}

然后重新构建即可.

方法二(所有项目)

在USER_HOME/.gradle/下创建init.gradle文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
allprojects{
repositories {
def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
def ALIYUN_JCENTER_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
url ALIYUN_JCENTER_URL
}
}
}

问题

1. 模拟器不能启动

问题日志:

1
2
3
Android Studio rants unable to load driver and AVD doesn’t start
libGL error: unable to load driver: i965_dri.so
libGL error: driver pointer missing

如何解决:

1
2
3
$ cd YOURPATH/Android/Sdk/emulator/lib64
$ mv libstdc++/ libstdc++.bak
$ ln -s /usr/lib64/libstdc++.so.6 libstdc++

参考链接:

Solve Android Studio AVD issue with Ubuntu distros

2. 手机驱动问题(真机模拟失败)

解决:(安装adb工具)

1
sudo apt-get install android-tools-adb android-tools-fastboot

参考链接:

Ubuntu 16.04 LTS - Install Android Tools (ADB, Fastboot & QtADB)