添加Barcode_Scan程序包后,无法构建Flutter应用程序

时间:2018-12-22 06:53:00

标签: android gradle kotlin visual-studio-code flutter

我是移动应用程序开发的新手,这是我对Flutter进行的首次试用。我正在尝试构建条形码扫描器应用程序,并且在添加了barcode_scan软件包并在项目中正确使用了它之后,它将无法成功构建。这是我得到的错误

  

无法获取'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin-api/1.2.51/kotlin-gradle-plugin-api-1.2.51.jar'。

     

连接到jcenter.bintray.com:443 [jcenter.bintray.com/5.153.35.248]失败:连接超时:连接   *尝试:   使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获取更多日志输出。与--scan一起运行以获取完整的见解。   *通过https://help.gradle.org获取更多帮助   在2m 47s内失败     命令:C:\ Flutter Solutions \ test_solution \ android \ gradlew.bat app:properties   请在android /文件夹中查看您的Gradle项目设置。

我知道找不到kotlin gradle插件。但是我不知道如何添加插件。我正在使用Visual Studio Code进行开发。请帮忙。

查看我的build.gradle文件

buildscript {
    ext.kotlin_version = '1.2.51'

    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

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

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

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

我认为添加ext.kotlin-versionclasspath依赖项会自动添加它,但是没有用。我需要指导。

2 个答案:

答案 0 :(得分:1)

它说“连接超时”,所以这不是真正的问题。您可以尝试添加比jcenter()更稳定的存储库。

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
        jcenter()
    }
}

答案 1 :(得分:0)

1) have you added this line in app build.gradle file 
   implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
   testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"

2) and for the plugin you have to go this step 

Android Studio → Preferences… →Plugins → Browse Repository → type “Kotlin” in search box → install

Step 2: Add Kotlin classpath to project Build.Gradle



buildscript {
    ext.kotlin_version = "1.1.1"
    ext.supportLibVersion = "25.3.0"
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"

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

    Step 3: Add Kotlin library and apply Kotlin Plugins in your module Build.gradle.

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    // ... various gradle setup
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile "com.android.support:appcompat-v7:$supportLibVersion"
    compile "com.android.support:recyclerview-v7:$supportLibVersion"
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}


**you can follow this link** 
https://medium.com/@elye.project/setup-kotlin-for-android-studio-1bffdf1362e8
https://kotlinlang.org/docs/reference/using-gradle.html#configuring-dependencies