首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尝试Flutter hello world代码时得到“无法应用插件[id 'kotlin-android']”

尝试Flutter hello world代码时得到“无法应用插件[id 'kotlin-android']”
EN

Stack Overflow用户
提问于 2020-08-08 17:52:08
回答 1查看 4.9K关注 0票数 2

我在尝试flutter的hello world代码。我是在遵循官方的from here文件。

Flutter版本:flutter_linux_1.20.1-稳定

我已经创建了flutter项目并点击run:

代码语言:javascript
复制
flutter create myapp
cd myapp
flutter run

但是它抛出了这个错误消息:

代码语言:javascript
复制
Launching lib/main.dart on R40 in debug mode...
                                                                        
FAILURE: Build failed with an exception.                                
                                                                        
* Where:                                                                
Build file '/home/sjs/flutter-projects/myapp/android/app/build.gradle' line: 25
                                                                        
* What went wrong:                                                      
A problem occurred evaluating project ':app'.                           
> Failed to apply plugin [id 'kotlin-android']                          
   > Could not create an instance of type org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension.
      > Could not generate a decorated class for class org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension.
         > org/jetbrains/kotlin/gradle/plugin/KotlinTarget              
                                                                        
* Try:                                                                  
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
                                                                        
* Get more help at https://help.gradle.org                              
                                                                        
BUILD FAILED in 18s                                                     
Running Gradle task 'assembleDebug'...                                  
Running Gradle task 'assembleDebug'... Done                        22.1s
Exception: Gradle task assembleDebug failed with exit code 1

下面是位于'/home/sjs/flutter-projects/myapp/android/app/':中的build.gradle文件

代码语言:javascript
复制
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.myapp"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

以下是flutter doctor -v的输出:

代码语言:javascript
复制
[✓] Flutter (Channel stable, 1.20.1, on Linux, locale en_US.UTF-8)
    • Flutter version 1.20.1 at /home/sjs/flutter
    • Framework revision 2ae34518b8 (2 days ago), 2020-08-05 19:53:19 -0700
    • Engine revision c8e3b94853
    • Dart version 2.9.0

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
    • Android SDK at /home/sjs/Android/Sdk
    • Platform android-30, build-tools 30.0.1
    • Java binary at: /home/sjs/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Android Studio (version 4.0)
    • Android Studio at /home/sjs/android-studio
    • Flutter plugin version 48.0.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (1 available)
    • R40 (mobile) • 00114604032517 • android-arm • Android 9 (API 28)

• No issues found!
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-11 22:27:55

好的,在这里找到了解决方案:https://github.com/react-native-community/react-native-webview/issues/1407#issuecomment-634436481

我不得不编辑<project-folder>/android/app/build.gradle文件。我已经换掉了这行

代码语言:javascript
复制
ext.kotlin_version = '1.3.50'

有了这个

代码语言:javascript
复制
ext.kotlin_version = '1.3.72'

然后运行了flutter run

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63314023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档