2

I've written an app in Flutter and have had no issues running it on iOS on both the simulator and a device. However, I'm having issues with Android. I come from an iOS and web background so it's likely my lack of Android knowledge that is giving me problems.

I followed the instructions in the Flutter Docs and installed Android Studio and added ANDROID_HOME to my PATH and bash profile.

I ran Android Studio and chose to install the Android SDK to an attached USB drive (formatted as an HFS+ Mac OS Extended (Journaled) volume). I don't believe that this should be causing me problems.

What happens:

  1. I succesfully launch the Android Simulator using

    flutter emulators --launch Nexus_5X_API_28_x86

  2. I key in

    flutter run

and then see the following output:

 Using hardware rendering with device Android SDK built for x86. If you get graphics artifacts, consider enabling software rendering with "--enable-software-rendering".
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...                                              1.0s
Resolving dependencies...                                          19.0s

FAILURE: Build failed with an exception.                                

* What went wrong:                                                      
Could not resolve all files for configuration ':app:debugCompileClasspath'.
> Could not find com.android.support:support-v4:27.0.3.    

Here's a screenshot of the whole error:

Full Compile error

This is my build.grade in android/app:

 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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 27

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "HIDDEN"
        minSdkVersion 26
        targetSdkVersion 27
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    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 {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

And this is the build.gradle in the android folder:

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
    }
}

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

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

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

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "27.0.3"
            }
        }
    }
}

And this is AndroidManifest.xml in android/app/src/main:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="HIDDEN">

    <!-- The INTERNET permission is required for development. Specifically,
         flutter needs it to communicate with the running application
         to allow setting breakpoints, to provide hot reload, etc.
    -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="HIDDEN"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
          </activity>
    </application>
</manifest>

This is the SDK manager in Android Studio correctly showing the SDK path and the installed SDKs.

Android Studio SDK Manager

All plugins in the project are up to date.

I feel that I'm probably missing something obvious here as this is simply talking about not being able to locate a file by the looks of it.

Any help much appreciated.

  • hi, take a look in this question. I think that's related to your issue https://stackoverflow.com/questions/54851489/flutter-projects-android-x-migration-issues/54857699#54857699 – Feu Mar 10 '19 at 13:46

0 Answers0