Android Studio - Error Building - Android tasks have already been created - android

Getting the following error when building the project:
Error:(2, 0) Android tasks have already been created.
This happens when calling android.applicationVariants,
android.libraryVariants or android.testVariants.
Once these methods are called, it is not possible to
continue configuring the model.
Root build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
apply plugin: 'android'
android {
compileSdkVersion 'Google Inc.:Google APIs:19'
buildToolsVersion '19.1.0'
defaultConfig {
versionCode 5
versionName '5'
targetSdkVersion 19
minSdkVersion 10
applicationId 'tsp.movil'
}
}
dependencies {
compile 'com.google.android.gms:play-services:7.0.0'
compile 'com.android.support:support-v4:22.1.1'
}
App build.gradle:
android {
compileSdkVersion 'Google Inc.:Google APIs:19'
buildToolsVersion '19.1.0'
defaultConfig {
applicationId "tsp.movil"
minSdkVersion 10
targetSdkVersion 19
versionCode 5
versionName '5'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile 'com.google.android.gms:play-services:+'
compile files('libs/zbar.jar')
}

Your Top Level build.gradle file should only have the configuration common for all modules of your project.
make the following changes :
Root build.gradle file should have only this piece of code
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects{
repositories {
jcenter()
}
}

I've faced a similar issue, with the same error message. The issue in my case was that I've had created a module inside a package and then deleted it manually in (MacOS) Finder.
The problem was that I forgot to also remove the include ::myModule line from the settings.gradle file.

look on this:
How to define common android properties for all modules using gradle
the 3rd comment says Android tasks have already been created. This happens when calling android.applicationVariants, android.libraryVariants or android.testVariants. Once these methods are called, it is not possible to continue configuring the model.

Related

How to import android github example with repositories and dependencies definitions

I know there are similar questions like this but i'm new in android development and i need to learn how to import an example defining repositories and dependencies in the build.gradle project file.
After several tries i can't figure out which is the right way...
The example is this one https://github.com/neokree/MaterialNavigationDrawer
When i load the project in android studio i get an error "Configuration with name 'default' not found.", and it's ok.. i know that i have to modify the build.grandle file
repositories {
mavenCentral()
}
dependencies {
compile 'it.neokree:MaterialNavigationDrawer:1.3.3'
}
But where i have to add/replace these rows? In the buildscript area? in the allprojects? i get "Gradle DSL method not found: 'compile()'" error or fix plugin version alert if i try to change something.
original build.grandle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
}
Your problem is in setting.gradle file in the MaterialNavigationDrawer project. As you can see
include ':app', ':MaterialNavigationDrawerModule'
it requires MaterialNavigationDrawerModule project to build. Go to New > Import Module and import MaterialNavigationDrawerModule.
Update build.gradle in MaterialNavigationDrawer\app to
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "it.neokree.materialnavigationdrawer"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName '1.0'
}
buildTypes {
release {
//runProguard false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
compile project(':MaterialNavigationDrawerModule')
}
Update build.gradle in MaterialNavigationDrawer\MaterialNavigationDrawerModule to
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName 'dev'
}
buildTypes {
release {
}
}
productFlavors {
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.balysv:material-ripple:1.0.1'
}
In MainActivity i deleted missing import
and rewrite Intent
to
Now it's working.

Can not import facebook-sdk 4.0.1

I have android studio 1.1.0 and i just created a new project and i'm trying to import new facebook-sdk 4.0.1 but can not do this, I followed Facebook Getting Started
But can not get it work. My app structure
My build.gradle(Project: MyApplication) file is:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
//mavenCentral()
}
}
My build.gradle(Module: app) file is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.hema.myapplication"
minSdkVersion 9
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.facebook.android:facebook-android-sdk:4.0.1'
}
Finally the error message is:
Error:(28, 13) Failed to resolve: com.facebook.android:facebook-android-sdk:4.0.1
Show in File<br>Show in Project Structure dialog
Edit I added mavenCentral() in the repositories closure in build.gradle(Project: MyApplication) file but not working with same error message.
I solved the problem, It was in my Gradle settings >> Unchecked Offline work
Actually i got the same problem and i solved it ..
1 : File > Import Module ..find facebook-android-sdk-4.0.1 then Finish
2 : Go to File > Project sturucture > dependecies tab > Module Dependencies select :facebook
3 : SYNC project and Rebuild
IF you got error like Could not find property 'ANDROID_BUILD_MIN_SDK_VERSION after rebuilding
go to facebook/build.gradle and change this part
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
to your sdk version like
compileSdkVersion 21
buildToolsVersion '21.1.1'
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
Add mavenCentral() in the repositories closure in your build.gradle file and sync.
Connect your laptop or computer with Internet connection.
It happened with me. I tried everything but at last when I commented laptop with Internet connection it worked.

Debug has an indirect dependency on Android API level X, but minSdkVersion for variant 'debug' is API level Y

I have a Android project created with Android Studio. I have added some third party dependencies to the project, but when I try to compile in Android Studio I hit the following error:
Error:Execution failed for task ':app:prepareDebugDependencies'.
> ERROR: Debug has an indirect dependency on Android API level 14, \
but minSdkVersion for variant 'debug' is API level 8
Compiling on the command line with ./gradlew works fine.
What does this error mean?
How do I fix it?
Many thanks.
UPDATE:
My top level build.gradle file:
[snowch#laptop MyApplication]$ cat build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenLocal()
mavenCentral()
maven { url "http://maven.restlet.org" }
}
}
The application module's build.gradle:
[snowch#laptop MyApplication]$ cat app/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.snowch.myapplication"
minSdkVersion 8
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'net.christophersnow:sync-android-p2p:0.0.1-SNAPSHOT'
compile("org.restlet.jse:org.restlet:2.1-M7") {
exclude group: 'org.osgi', module: 'org.osgi.core'
}
compile("org.restlet.jse:org.restlet.ext.simple:2.1-M7")
}
Setting the minSdkVersion to 14 in the app\build.gradle file fixed the issue for me.
Thanks to murtaza-hussain and gabriele-mariotti for the inspiration.

Error:Artifact 'support-v4.jar (com.android.support:support-v4:21.0.3)' not found. Android studio 1.0.2

I did a new install of Android Studio 1.0.2. Getting the following error when opening my first existing android project:
Gradle 'MyApplication' project refresh failed
Error:Artifact 'support-v4.jar (com.android.support:support-v4:21.0.3)' not found.
Searched in the following locations: file:/C:/Users/Ntokozo/AppData/Local/Android/sdk/extras/android/m2repository/com/android/support/support-v4/21.0.3/support-v4-21.0.3.jar
And if I navigate to that searched location I found two jar files which are: support-v4-21.0.3-sources.jar and support-v4-21.0.3-javadoc.jar
Here is my build.gradle file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Gradle file under App folder:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.ntokozo.myapplication"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
}
Thank you in advance, please bare in mind in responses that I'm a novice and I might not know advanced features.
After re-installing windows OS and a new Android Studio setup the problem disappeared. I don't know what was the problem at first.

Can't integrate AdMob in my app (Android Studio)

I need to implement AdMob in my project, so first I wanted to set up Google Play Services
Did everything as on official site:
-Download latest (4.4.52) Google Play Services in SDK manager
-In build.gradle in dependencies added
compile 'com.google.android.gms:play-services:4.4.52'
Got this error when sync project:
Error:A problem occurred configuring project ':app'.
Could not resolve all dependencies for configuration ':app:_debugCompile'.
Could not find com.google.android.gms:play-services:4.4.52.
Required by:
MyApplication:app:unspecified
Please, help
Please check your build.gradle and make sure that the mavenCentral reposority is included. Your file should look something like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.+'
compile 'com.google.android.gms:play-services:4.4.52'
}

Categories

Resources