Pidikan
Pidikan

Reputation: 303

Android - Google APIs - Error detecting SDK

I have a problem on an Android studio project. The project is compiled with Google APIs 24, but I can't run it from Android Studio. I'm able to build the project and generate an APK, and if I install it manually or with ADB, it works like a charm. But if I try to run the project on AS, the run configuration popup is opened with the error "Please select Android SDK". When I click on Run, the message "Configuration is still incorrect. Do you want to edit it again ?" appears and I can click on "Continue anyway", which gave me the error "Error running app: Please select Android SDK". If I go on the project structure, the compile SDK version is "Google APIs, Android 24 (API 24)", which is what I want.

Here is my build.gradle file :

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'Google Inc.:Google APIs:24'
    buildToolsVersion '25'

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 22 // SDK 23 /!\ Permissions handling

        versionCode 52
        versionName "1.6"
        applicationId "com.myapp.app"

        multiDexEnabled true
    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    signingConfigs {
        release {
            ...
        }
    }

    buildTypes {
        debug {
            minifyEnabled false
            applicationIdSuffix '.debug'
            versionNameSuffix '-DEBUG'
        }

        release {
            signingConfig signingConfigs.release
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
        }
    }

    lintOptions {
        abortOnError false
    }
    useLibrary 'org.apache.http.legacy'
}

repositories {
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    compile 'com.android.support:support-v4:24.2.1'
    compile 'com.squareup.okhttp3:okhttp:3.3.1'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.android.support:design:24.2.1'
    compile 'com.android.support:mediarouter-v7:24.2.1'
    compile 'com.android.support:recyclerview-v7:24.2.1'
    compile 'com.android.support:preference-v7:24.2.1'
}

Also, I think it's the same problem, on an xml file, the preview doesn't work. The editor API version is null and none are proposed in the selection. All I can select is "Automatically pick best" which does nothing. I also have a "Unknown attribute warning on each attribute.

I have this problem on a Mac mini with the last version of Yosemite OS. Even after formatting and reinstalling AS and Android SDK, the problem is still here, but I didn't have it few weeks ago. And on a Macbook pro on El Captain, it works fine.

Does someone know about this problem ?

Upvotes: 2

Views: 908

Answers (2)

Todor Balabanov
Todor Balabanov

Reputation: 388

I did solve the same problem by changing few times the SDK version of the "app" build. It seems that after few changes the IDE fixed the configuration files. The advantage of this fixing is that new project creation and file migrations are not needed.

Upvotes: 0

Pidikan
Pidikan

Reputation: 303

Fix 1 - Found for Mac OS:

  1. Create a new project on Android Studio
  2. Copy build.gradle files from the previous project to the new one
  3. Copy AndroidManifest file and res and java folders from the previous project to the new one
  4. Copy the others necessary folders (assets, libs, ...) from the previous project to the new one

Rebuild the project after each steps to be sure the Run button doesn't have the red "X".

Fix 2 - Found for Windows by @user1608385:

  1. Rename the SDK folder in C:\Users\MYUSERNAME\AppData\Local\Android to something else
  2. Open Android Studio and pointed it towards the newly named folder

Maybe this solution works also for Mac OS, I didn't try.

EDIT : There is an opened issue on the AOSP Issue tracker : https://code.google.com/p/android/issues/detail?id=203729&can=1

Upvotes: 3

Related Questions