简体   繁体   中英

Flutter Application Won't Build After Adding Barcode_Scan Package

I'm new to mobile app development and this is my first trial with Flutter. I am trying to build a barcode scanner app and after adding the barcode_scan package and using it appropriately in the project, it would not build successfully. This is the error I get below

Could not GET ' https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin-api/1.2.51/kotlin-gradle-plugin-api-1.2.51.jar '.

Connect to jcenter.bintray.com:443 [jcenter.bintray.com/5.153.35.248] failed: Connection timed out: connect * 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 2m 47s Command: C:\\Flutter Solutions\\test_solution\\android\\gradlew.bat app:properties Please review your Gradle project setup in the android/ folder.

I know kotlin gradle plugin cannot be found. But I have no idea of how to add the plugin. I am using Visual Studio Code for development. Please help.

See my build.gradle file

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
}

I thought adding ext.kotlin-version and the classpath dependency will automatically add it but that didn't work. I need guidance.

Well it said "connection timed out" so that's not really a problem; you can try to add more repositories that are more stable than jcenter().

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
        jcenter()
    }
}
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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM