2018年3月9日 星期五

Android Studio 舊專案升級到 Android Studio 3.0 的嘗試項目


舊版專案更新步驟


1. 到 Project 的 build.gradle 加上 maven google:


// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
        }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

        // NOTE: Do not place your application dependencies here; they belong        // in the individual module build.gradle files    }
}

allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}


2. 修改 gradle-wrapper.properties 參數,使用新版的 gradle


#Fri Mar 02 17:00:45 CST 2018distributionBase=GRADLE_USER_HOMEdistributionPath=wrapper/distszipStoreBase=GRADLE_USER_HOMEzipStorePath=wrapper/distsdistributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

3. 把 project 整合到其他 project


如果要變成 Library ,要在 app 的 build.gradle 把第一行的 apply plugin: 'com.android.application' 改成 apply plugin 'com.android.library' ,然後記得把 defaultConfig 設定裡面,把 applicationId 拿掉。

4. 在 gradle.properties 設定 AAPT2:

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:# Gradle settings configured through the IDE *will override*# any settings specified in this file.
# For more details on how to configure your build environment visit# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.# The setting is particularly useful for tweaking memory settings.org.gradle.jvmargs=-Xmx1536m
storeFile=../../../../../.android/debug.keystorestorePassword=androidkeyAlias=androiddebugkeykeyPassword=android
android.enableAapt2=false


問題處理


unknown element <permission> found. Error


在 gradle.properties 裡面設定:

android.enableAapt2=false

No resource found that matches the given name '@style/Theme.AppCompat.Light'


AndroidManifest.mxl 裡面設定:

minSdkVersion < 14

Error: Unable to find method ‘org.gradle.api.internal.project.ProjectInternal.getPluginManager()Lorg/gradle/api/internal/plugins/PluginManagerInternal;’. Possible causes for this unexpected error include:


在 gradle-wrapper.properties 裡面設定:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip


Reference:
[1] http://blog.csdn.net/wolfking0608/article/details/78792700
[2] https://www.jianshu.com/p/6ad7864e005e
[3] http://blog.csdn.net/ouyang_peng/article/details/52027668
[4] https://github.com/vmlinz/stackoverflow-android-top100-faqs/wiki/001-how-to-fix-android-os-network-on-mainthread-exception

沒有留言:

張貼留言

© ERIC RILEY , 自由無須告知轉貼
Background Japanese Sayagata by Olga Libby