Android Studio 2.0 to Android Studio 3.0

本文转自 https://www.codexpedia.com/android/android-studio-2-0-to-android-studio-3-0/


When importing Android project that was using gradle 2+ and Android Studio 2+ into Android Studio 3.0, Android Studio 3.0 might run into this error.

Error:Could not initialize class org.jetbrains.kotlin.kapt.idea.KaptModelBuilderService

Replace following project gradle file which uses gradle 2.2.2

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

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

with this project gradle file to use grade 3.0.0 to work with Android Studio 3.0+

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.1.60'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

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

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

In the app gradle file, replace these plugins with

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.neenbedankt.android-apt'

these plugins.

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'

In the dependencies tag in the app gradle file, replace compile to implementation, replace testCompile with testImplementation, replace androidTestCompile with androidTestImplementation

For projects using dagger 2. replace

compile 'com.google.dagger:dagger:2.7'
apt 'com.google.dagger:dagger-compiler:2.7'
provided 'javax.annotation:jsr250-api:1.0'
<pre>

with
<pre>
implementation "com.google.dagger:dagger:2.11"
implementation "com.google.dagger:dagger-android:2.11"
kapt "com.google.dagger:dagger-compiler:2.11"

Now you will probably get this error if you haven’t upgraded the gradle library in the gradle-wrapper.properties file.
Could not find method google() for arguments [] on repository container.

So, let’s replace this line in the gradle-wrapper.properties

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

with this line

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

Then do a clean and rebuild, everything should work now.

Android Studio是Google官方开发的集成开发环境(IDE),专门用于Android应用开发。自发布以来,Android Studio经历了多个版本的更新,每个版本都带来了新功能、性能改进以及对Android新特性的支持。以下是一些关键版本的介绍: 1. Android Studio 1.0:这是Android Studio的第一个正式版本,于2014年发布。它提供了基于IntelliJ IDEA的集成开发环境,集成了Android SDK和模拟器,支持多种设备和屏幕尺寸的预览,以及Gradle构建工具等。 2. Android Studio 2.0:该版本引入了Instant Run功能,可以快速部署应用的修改,提高了开发效率。同时,引入了App Indexing API,帮助应用提升在Google搜索中的可见性。 3. Android Studio 3.0:此版本重点改进了对Kotlin的支持,并将Kotlin集成为Android应用开发的官方语言之一。此外,引入了新的布局编辑器,支持更多的布局属性和自定义视图。 4. Android Studio 3.5:该版本是Android Studio的一个重要更新,主要改进了代码编辑器的性能,支持了更高效的代码完成和搜索。同时,改进了对Dagger和Room等依赖注入库的支持。 5. Android Studio 4.0:随着Android 11的发布,Android Studio 4.0也带来了对新版本API的支持。它改进了对Jetpack Compose的支持,这是一种用于构建原生界面的新框架。同时,增强了对5G应用的开发工具。 6. Android Studio Arctic Fox(目前的稳定版本):在Android Studio的版本命名中,引入了以动物为代号的命名方式。Arctic Fox带来了对Android 12的支持,新的布局编辑器功能,以及对应用捆绑和应用内购买的改进。 每个版本的Android Studio都包含了许多小更新和修复,但主要的新功能和改进通常在主要版本更新中出现。开发者应定期更新到最新版本,以便利用最新的工具和功能,提高开发效率和应用性能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值