当前位置: 代码迷 >> Android >> Ubuntu环境配置集锦:(七)配置AndroidStudio
  详细解决方案

Ubuntu环境配置集锦:(七)配置AndroidStudio

热度:54   发布时间:2016-04-28 04:42:35.0
Ubuntu环境配置汇总:(七)配置AndroidStudio

1. 构建新项目,gradle下载不成功的问题。

创建新项目的时候,提示一直下载gradle,但是无法下载成功。

1)首先,去gradle的官网下载压缩包。

http://www.gradle.org/downloads

gradle-1.12-all.zip


2)把下载好的gradle-1.12-all.zip拷贝到~/.gradle/wrapper/dists/gradle-1.12-all/2apkk7d25miauqf1pdjp1bm0uo

注:如果用AS创建过新的工程,那么AS会自动创建这个目录。


3)重新打开AS,等待AS自动完成gradle的配置。

下面是终端里面AS的工作日志,可以看出,首先AS会解压gradle-1.12-all.zip,然后下载一些依赖的jar。

Unzipping /home/kaizen/.gradle/wrapper/dists/gradle-1.12-all/2apkk7d25miauqf1pdjp1bm0uo/gradle-1.12-all.zip to /home/kaizen/.gradle/wrapper/dists/gradle-1.12-all/2apkk7d25miauqf1pdjp1bm0uoSet executable permissions for: /home/kaizen/.gradle/wrapper/dists/gradle-1.12-all/2apkk7d25miauqf1pdjp1bm0uo/gradle-1.12/bin/gradle16:14:10.417 [Connection worker] DEBUG o.g.t.i.provider.DefaultConnection - Tooling API provider 1.12 created.16:14:10.724 [Connection worker] DEBUG o.g.t.i.provider.ProviderConnection - Configuring logging to level: INFOTooling API is using target Gradle version: 1.12.Could not determine classpath for class org.gradle.util.GradleVersionCould not determine classpath for class org.slf4j.LoggerFactoryStarting Gradle daemonStarting daemon process: workingDir = /home/kaizen/.gradle/daemon/1.12, daemonArgs: [/home/kaizen/developer/jdk1.6.0_45/bin/java, -XX:MaxPermSize=256m, -XX:+HeapDumpOnOutOfMemoryError, -Xmx1024m, -Dfile.encoding=UTF-8, -cp, /home/kaizen/.gradle/wrapper/dists/gradle-1.12-all/2apkk7d25miauqf1pdjp1bm0uo/gradle-1.12/lib/gradle-launcher-1.12.jar, org.gradle.launcher.daemon.bootstrap.GradleDaemon, 1.12, /home/kaizen/.gradle/daemon, 10800000, 57c7e4ac-85a2-40cd-92ea-79aed2105b46, -XX:MaxPermSize=256m, -XX:+HeapDumpOnOutOfMemoryError, -Xmx1024m, -Dfile.encoding=UTF-8]Starting process 'Gradle build daemon'. Working directory: /home/kaizen/.gradle/daemon/1.12 Command: /home/kaizen/developer/jdk1.6.0_45/bin/java -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=UTF-8 -cp /home/kaizen/.gradle/wrapper/dists/gradle-1.12-all/2apkk7d25miauqf1pdjp1bm0uo/gradle-1.12/lib/gradle-launcher-1.12.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 1.12 /home/kaizen/.gradle/daemon 10800000 57c7e4ac-85a2-40cd-92ea-79aed2105b46 -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=UTF-8Successfully started process 'Gradle build daemon'An attempt to start the daemon took 0.662 secs.Connected to the daemon. Dispatching Build{id=9b20f5b5-b8e0-4861-846e-f33d4ded552f.1, currentDir=/home/kaizen/AndroidStudioProjects/MyApplication} request.Download http://jcenter.bintray.com/com/android/tools/build/gradle/0.12.2/gradle-0.12.2.pomDownload http://jcenter.bintray.com/com/android/tools/lint/lint/23.0.2/lint-23.0.2.pomDownload http://jcenter.bintray.com/com/android/tools/build/builder/0.12.2/builder-0.12.2.pomDownload http://jcenter.bintray.com/com/android/tools/lint/lint-checks/23.0.2/lint-checks-23.0.2.pomDownload http://jcenter.bintray.com/com/android/tools/sdk-common/23.0.2/sdk-common-23.0.2.pomDownload http://jcenter.bintray.com/com/android/tools/build/builder-model/0.12.2/builder-model-0.12.2.pomDownload http://jcenter.bintray.com/com/android/tools/ddms/ddmlib/23.0.2/ddmlib-23.0.2.pomDownload http://jcenter.bintray.com/com/android/tools/build/manifest-merger/23.0.2/manifest-merger-23.0.2.pomDownload http://jcenter.bintray.com/com/android/tools/sdklib/23.0.2/sdklib-23.0.2.pomDownload http://jcenter.bintray.com/com/android/tools/common/23.0.2/common-23.0.2.pomDownload http://jcenter.bintray.com/com/android/tools/build/builder-test-api/0.12.2/builder-test-api-0.12.2.pomDownload http://jcenter.bintray.com/com/android/tools/lint/lint-api/23.0.2/lint-api-23.0.2.pomDownload http://jcenter.bintray.com/com/android/tools/layoutlib/layoutlib-api/23.0.2/layoutlib-api-23.0.2.pomDownload http://jcenter.bintray.com/com/android/tools/dvlib/23.0.2/dvlib-23.0.2.pomDownload http://jcenter.bintray.com/com/android/tools/build/gradle/0.12.2/gradle-0.12.2.jar[ 243945]   WARN - api.vfs.impl.local.FileWatcher - Watcher terminated with exit code 0 [email protected]:~/professional/android-studio/bin$ [email protected]:~/professional/android-studio/bin$ [email protected]:~/professional/android-studio/bin$ ./studio.sh Fontconfig warning: "/etc/fonts/conf.d/50-user.conf", line 9: reading configurations from ~/.fonts.conf is deprecated.Fontconfig warning: "/etc/fonts/conf.d/50-user.conf", line 9: reading configurations from ~/.fonts.conf is deprecated.SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".SLF4J: Defaulting to no-operation (NOP) logger implementationSLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.Unzipping /home/kaizen/.gradle/wrapper/dists/gradle-1.12-all/2apkk7d25miauqf1pdjp1bm0uo/gradle-1.12-all.zip to /home/kaizen/.gradle/wrapper/dists/gradle-1.12-all/2apkk7d25miauqf1pdjp1bm0uoSet executable permissions for: /home/kaizen/.gradle/wrapper/dists/gradle-1.12-all/2apkk7d25miauqf1pdjp1bm0uo/gradle-1.12/bin/gradle16:28:28.487 [Connection worker] DEBUG o.g.t.i.provider.DefaultConnection - Tooling API provider 1.12 created.16:28:28.762 [Connection worker] DEBUG o.g.t.i.provider.ProviderConnection - Configuring logging to level: INFOTooling API is using target Gradle version: 1.12.Could not determine classpath for class org.gradle.util.GradleVersionCould not determine classpath for class org.slf4j.LoggerFactoryStarting Gradle daemonStarting daemon process: workingDir = /home/kaizen/.gradle/daemon/1.12, daemonArgs: [/home/kaizen/developer/jdk1.6.0_45/bin/java, -XX:MaxPermSize=256m, -XX:+HeapDumpOnOutOfMemoryError, -Xmx1024m, -Dfile.encoding=UTF-8, -cp, /home/kaizen/.gradle/wrapper/dists/gradle-1.12-all/2apkk7d25miauqf1pdjp1bm0uo/gradle-1.12/lib/gradle-launcher-1.12.jar, org.gradle.launcher.daemon.bootstrap.GradleDaemon, 1.12, /home/kaizen/.gradle/daemon, 10800000, b97e7dd0-c6d2-45f6-bb26-3598cdac5ec3, -XX:MaxPermSize=256m, -XX:+HeapDumpOnOutOfMemoryError, -Xmx1024m, -Dfile.encoding=UTF-8]Starting process 'Gradle build daemon'. Working directory: /home/kaizen/.gradle/daemon/1.12 Command: /home/kaizen/developer/jdk1.6.0_45/bin/java -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=UTF-8 -cp /home/kaizen/.gradle/wrapper/dists/gradle-1.12-all/2apkk7d25miauqf1pdjp1bm0uo/gradle-1.12/lib/gradle-launcher-1.12.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 1.12 /home/kaizen/.gradle/daemon 10800000 b97e7dd0-c6d2-45f6-bb26-3598cdac5ec3 -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -Xmx1024m -Dfile.encoding=UTF-8Successfully started process 'Gradle build daemon'An attempt to start the daemon took 0.647 secs.Connected to the daemon. Dispatching Build{id=23bf2872-969b-4499-a311-e96b50cf9695.1, currentDir=/home/kaizen/AndroidStudioProjects/MyApplication} request.Download http://jcenter.bintray.com/com/android/tools/build/gradle/0.12.2/gradle-0.12.2.jarDownload http://jcenter.bintray.com/com/android/tools/lint/lint/23.0.2/lint-23.0.2.jarDownload http://jcenter.bintray.com/com/android/tools/build/builder/0.12.2/builder-0.12.2.jarDownload http://jcenter.bintray.com/com/android/tools/lint/lint-checks/23.0.2/lint-checks-23.0.2.jarDownload http://jcenter.bintray.com/com/android/tools/sdk-common/23.0.2/sdk-common-23.0.2.jarDownload http://jcenter.bintray.com/com/android/tools/build/builder-model/0.12.2/builder-model-0.12.2.jarDownload http://jcenter.bintray.com/com/android/tools/ddms/ddmlib/23.0.2/ddmlib-23.0.2.jarDownload http://jcenter.bintray.com/com/android/tools/build/manifest-merger/23.0.2/manifest-merger-23.0.2.jarDownload http://jcenter.bintray.com/com/android/tools/sdklib/23.0.2/sdklib-23.0.2.jarDownload http://jcenter.bintray.com/com/android/tools/common/23.0.2/common-23.0.2.jarDownload http://jcenter.bintray.com/com/android/tools/build/builder-test-api/0.12.2/builder-test-api-0.12.2.jarDownload http://jcenter.bintray.com/com/android/tools/lint/lint-api/23.0.2/lint-api-23.0.2.jarDownload http://jcenter.bintray.com/com/android/tools/layoutlib/layoutlib-api/23.0.2/layoutlib-api-23.0.2.jarDownload http://jcenter.bintray.com/com/android/tools/dvlib/23.0.2/dvlib-23.0.2.jarDownload http://jcenter.bintray.com/com/android/tools/build/gradle/0.12.2/gradle-0.12.2-sources.jarDownload http://jcenter.bintray.com/net/sf/proguard/proguard-base/4.11/proguard-base-4.11-sources.jarDownload http://jcenter.bintray.com/net/sf/proguard/proguard-gradle/4.11/proguard-gradle-4.11-sources.jarDownload http://jcenter.bintray.com/com/android/tools/common/23.0.2/common-23.0.2-sources.jarDownload http://jcenter.bintray.com/com/android/tools/layoutlib/layoutlib-api/23.0.2/layoutlib-api-23.0.2-sources.jarDownload http://jcenter.bintray.com/com/android/tools/dvlib/23.0.2/dvlib-23.0.2-sources.jarDownload http://jcenter.bintray.com/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1-sources.jarDownload http://jcenter.bintray.com/com/android/tools/sdklib/23.0.2/sdklib-23.0.2-sources.jarDownload http://jcenter.bintray.com/com/android/tools/sdk-common/23.0.2/sdk-common-23.0.2-sources.jarDownload http://jcenter.bintray.com/com/android/tools/build/builder-model/0.12.2/builder-model-0.12.2-sources.jarDownload http://jcenter.bintray.com/com/android/tools/lint/lint-api/23.0.2/lint-api-23.0.2-sources.jarDownload http://jcenter.bintray.com/com/android/tools/lint/lint-checks/23.0.2/lint-checks-23.0.2-sources.jarDownload http://jcenter.bintray.com/com/android/tools/lint/lint/23.0.2/lint-23.0.2-sources.jarDownload http://jcenter.bintray.com/com/android/tools/ddms/ddmlib/23.0.2/ddmlib-23.0.2-sources.jarDownload http://jcenter.bintray.com/com/android/tools/build/manifest-merger/23.0.2/manifest-merger-23.0.2-sources.jarDownload http://jcenter.bintray.com/com/android/tools/build/builder-test-api/0.12.2/builder-test-api-0.12.2-sources.jarDownload http://jcenter.bintray.com/com/squareup/javawriter/2.5.0/javawriter-2.5.0-sources.jarDownload http://jcenter.bintray.com/com/android/tools/build/builder/0.12.2/builder-0.12.2-sources.jarBUILD SUCCESSFULTotal time: 2 mins 4.164 secsCreating ClassLoader cda10f2c-7a96-43f6-ac02-439fb293d088 from system and [[email protected]].Creating ClassLoader 8b556d42-4196-4015-bfce-da42e83769a2 from [email protected]8 and [[email protected]].Creating ClassLoader 9e1e2c21-8d2b-41c0-8be0-3a6ce81cc7d9 from [email protected]d2 and [org.gradle.tooling.internal.provider.ModelClassLoaderFactory$MixI[email protected]].Creating ClassLoader cd6a6514-3fb0-480b-9a70-33a8541439a2 from [email protected]7a and [org.gradle.tooling.internal.provider.ModelClassLoaderFactory$MixI[email protected]].Creating ClassLoader ff37e9e6-b1e6-4a5e-b18e-287576d9a310 from [email protected]20 and [org.gradle.tooling.internal.provider.ModelClassLoaderFactory$MixI[email protected], [email protected][email protected]].Creating ClassLoader 7b578a69-cddf-4fdc-95b1-7758c69fbef7 from [email protected] and [[email protected]].Creating ClassLoader e709f50c-8ca2-4171-b07f-a1dd73c210cf from [email protected]6 and [[email protected]].Creating ClassLoader f910b95f-21b9-4b2d-b43d-28f848b37393 from [email protected]7 and [org.gradle.tooling.internal.provider.ModelClassLoaderFactory$MixI[email protected]].Creating ClassLoader 7aaf8593-ee35-4293-84b7-843ba0953f7f from [email protected] and [[email protected]].Creating ClassLoader bb9fe68f-796f-4102-8b5d-e105b443192d from [email protected]46 and [[email protected]].Creating ClassLoader 66239886-3a13-41f1-8437-e537c3e37cdc from [email protected]91 and [org.gradle.tooling.internal.provider.ModelClassLoaderFactory$MixI[email protected]].Creating ClassLoader ddf28e42-1797-4bba-8684-077d81c64b2b from [email protected]35 and [[email protected]].Tooling API is using target Gradle version: 1.12.Tooling API is using target Gradle version: 1.12.Connected to the daemon. Dispatching Build{id=494ecf74-c1e3-48a1-a1b7-6c91646db023.1, currentDir=/home/kaizen/AndroidStudioProjects/MyApplication} request.Configuration on demand is an incubating feature.:app:preBuild:app:preDebugBuild:app:checkDebugManifest:app:prepareDebugDependencies:app:compileDebugAidl:app:compileDebugRenderscript:app:generateDebugBuildConfig:app:generateDebugAssets UP-TO-DATE:app:mergeDebugAssets:app:generateDebugResValues:app:generateDebugResources:app:mergeDebugResources:app:processDebugManifest:app:processDebugResources:app:generateDebugSourcesBUILD SUCCESSFULTotal time: 3.249 secs


2. 使用gradle编译安装apk,出现INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION 的问题。

在AndroidManifest.xml中配置<uses-sdk/>标签:

<uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="15" />
但是,编译安装时会报错。

随后,发现build.gradle文件中是这样配置的:

apply plugin: 'com.android.application'android {    compileSdkVersion 19    buildToolsVersion "19.1.0"    defaultConfig {        applicationId "com.example.kaizen.myapplication"        minSdkVersion 15        targetSdkVersion 19        versionCode 1        versionName "1.0"    }    buildTypes {        release {            runProguard false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }    }}dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])}

修改minSdkVersion 8,重新编译安装成功,不再报错。