Flutter Android Studio Troubleshooting: Could not Compile Flutter to Android device

This error also known as:

  • Device selection on Android Studio is greyed out.
  • Not applicable for the “main.dart” configuration.
  • Could not connect to lockdownd, error code -13.

What’s the symptom?

You will see this issue when you’re trying to compile to your Android device via Android Studio, but for some strange reason, you no longer see your mobile device to the left of “main.dart” dropdown.

Yep, no longer you see the leftmost dropdown.

You’ll instinctly When you move your mouse toward the third dropdown (or in your case, the second dropdown since the leftmost isn’t there), and see a popup saying “Not applicable for the “main.dart” configuration, and it isn’t clickable (of course).

You can attach any number of devices, but the leftmost dropdown will still not be there.

Because the problem is not in your device. There’s actually something wrong with your project’s SDK configuration, which prevent Android Studio from recognizing entry point, or recognizing what framework it is.

Now I don’t know whether this issue also appears on pure Android app using Java/Kotlin, but I only encounter this on Flutter on Android Studio.

How to solve this?

Open menu File > Project Structure.

First, choose the Project menu under Project Settings. You’ll see settings about Project SDK. It should says Android API level. But sometimes, once in a blue moon, it can says “<NO SDK>”.

The obvious thing to do here is to click on the Project SDK dropdown, and select whichever latest SDK listed there.

Next, choose the Modules menu under Project Settings. You’ll see your modules listed on the second column.

Select any module, and then look on the third column, where it has three tabs: Sources, Paths, Dependencies. Choose Dependencies.

Now, once again, once in a blue moon, the Module SDK can suddenly select “<NO SDK>”. Choose the same latest SDK you choose on the Project settings, which in my case, is Android API 29 Platform.

Repeat this for every module you have on the second column.

If you have done, click OK to close the screen.

Now, the Android Studio will adjusting itself to the new settings, and you’re (hopefully) will see the device selection to the left of the “main.dart” dropdown, which will indicate that you now able to compile to the device selected.

Hope it helps! If you have any other issue, leave it in comment below and see if I can help you. Thanks!

Source: https://flutterforum.co/t/emulator-field-grayed-out-not-applicable-for-the-main-dart-configuration/317/9

How to add “Application Entry Point” in Kotlin

Coming from iOS developer perspective, I’m accustomed with the fact that when I create new project, there’s this file/class called AppDelegate automatically created for me. Code inside AppDelegate function didFinishLaunchingWithOptions: is guaranteed to be run ahead first before any other code except global variable initializations. Putting code in the AppDelegate is crucial because you can just put code there without care about which ViewController class gets displayed as root.

When developing Kotlin, I missed this feature. Turns out, it exists, but it doesn’t created for you automatically. You have to make it yourself. Luckily, it’s not hard. Unluckily, if you don’t use it frequently, you may forget about this. When you do forget, sometimes searching on the internet for “Kotlin Application Entry” does not lead you to what you’re searching for. So, here I am, making this short note, to remind me and you visitors about this. Something like main(). But what I’m about to show you is not main(), but something similar.

I assume you already have created a new project for this, in Kotlin. But this is actually can be done in Java too.

1. Create the file

Switch the navigation into Android. Go to your project files, and create a new file. Name it whatever. I named it ApplicationEntry.

2. Create the class

The application entry class must be a descendant of class Application. Don’t forget to make necessary import by pressing CMD+Enter or CTRL+Enter.

import android.app.Application

class ApplicationEntry() : Application() {
    
}

3. Create the initializer block

Using this, you can treat the class like any other class. That means, you can add initializer block on the class, which guaranteed will get called before any other code in your app (well, except global variable initializations, of course).

import android.app.Application

class ApplicationEntry() : Application() {

init {
// put any initialization here
}

}

4. Reference this class in Android Manifest

Without referencing this class in Android Manifest, Android wouldn’t even know that this class need to be run first.

You’ll see something like this on your code editor.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>

Add android:name=".ApplicationEntry" attribute to the application block, so it will looks like this: (make note of the dot sign before the name)

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.myapplication">

    <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:name=".ApplicationEntry"
            android:theme="@style/AppTheme">
        <activity
                android:name=".MainActivity"
                android:label="@string/app_name"
                android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

The autocomplete will help you to accomplish this.

So that’s it. I know this is trivia, but if you’re new to Kotlin and Android programming, sometimes your search doesn’t lead you to what you’re searching for. Thus I hope you stumbled upon this article and end your endless quest.

MPAndroidChart Explained in Kotlin

I am new to Kotlin and Android programming, and somehow I have a hard time to find a really basic MPAndroidChart plugin explanation. Finally, I found the tutorial from the plugin writer himself. You can read it here.

But I want to rewrite the tutorial from a different point of view, and hope that it can help you (especially all the Android dev beginners) to understand about the concept in a better flow.

Continue reading

GraphQL 101 Quick Start

GraphQL is the new database management from the Facebook team, which now outsourced. This article is a quick reference from what I’ve learned about it with autodidact. My article may miss some of the concepts as I can’t find a proper “for dummies” tutorial about GraphQL out there but should be sufficient for beginners as a stepping stone for more advanced concepts.

This GraphQL article is made using Graphcool as Server As A Service, and Apollo for the plugins. I’ll try to steer clear from a specific platform implementation, and just focused on GraphQL queries and mutations, as well as how to implement it in Apollo client. Feel free to skip over some steps if you’ve already done it.

Continue reading