The module 'app' is an Android project without build variants - android

I am getting below error while importing android project.
Error:The module 'app' is an Android project without build variants, and cannot be built.
Please fix the module's configuration in the build.gradle file and sync the project again.
Gradle file code.
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.djalel.android.bilal"
minSdkVersion 9
targetSdkVersion 25
versionCode 4
versionName "1.3"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
aaptOptions {
cruncherEnabled = false
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:25.3.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:25.3.1'
implementation 'com.android.support:support-v4:25.3.1'
implementation 'com.google.android.gms:play-services-location:12.0.1'
implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
implementation 'com.jakewharton.timber:timber:3.1.0'
}
repositories {
mavenCentral()
}
I checked with working gradle file as well but getting same error in this project.

Above gradle file code seems to be perfect. Probably its nothing to do with app/build.gradle (Module:app). Just open other build.gradle (Project:Android) file in Project window and verify your Android Studio version it must be same as yours.
I replaced from:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
to my Android Studio v3.0.1 in my case:
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Press "Try Again" to Sync gradle file. This resolved my problem with a successful build.

For me, this issue appeared when I updated Android Studio to version 3.3.
Disabling experimental feature "Only sync the active variant" fixes it:

Try use command line to run gradlew tasks to see why the build would fail.
In my case:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
platforms;android-27 Android SDK Platform 27
build-tools;27.0.3 Android SDK Build-Tools 27.0.3
So I just ran Go to Android\sdk\tools\bin sdkmanager --licenses to accept licenses and then the build passed in command line.
I think Android Studio is crying for the wrong issue. So you may check the real output in command line and find what is happening.

Just install the Android SDK platform package through SDK Manager in Android Studio, relevant to your Compile SDK version. It will prompt you to install the package as well as to accept the license. After that just sync the gradle, it will resolve the issue.

You must update your dependencies in build.grade in the buildscript block:
classpath 'com.android.tools.build:gradle:3.1.0'
to:
classpath 'com.android.tools.build:gradle:3.4.2'

If this error occurs for other module than 'app'
Remove gradle variable from that module's build.gradle like
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
& replace it actual value
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.71"
Clean Project -> Rebuild Project

I had this issue in my library project. I solved it by adding
buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
To the beginning of build.gradle

Related

gradle sync failed, read timeout error in android studio 3.3.1 for sample hello world app in

connection timeout error in gradle sync, in android studio 3.3 for sample hello world app in.
Earlier it was working with no proxy set in http setting in android studio settings.
I have tried other solution from stack overflow. looks like gradle can't download from all urls.
now reinstalling studio after completely uninstalling it.
Update
after reinstalling the problem persists.
SOMETIME build clean from GUI does not do anything at all.
Project level Build.gradle file
** Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
**
App level build.graldle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
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'
}
Update
After formatting my windows 10 and freshly installed development tools, it now throws Gradle Sync Failed: Read timeout error
Its Network issue fails to build pass offline argument in Gradle
Try ./gradlew tasks --offline
For run Android project in offline mode visit GRADLE CLI docs : Gradle
Android Studio
In Android, studio can make Gradle to build your project in offline mode options :
Settings -- Build, Execution, Deployment -- Build tools -- Gradle
Gradle Offline Android
Solution: that worked for me
setting -
language and framework -
kotlin -
update kotlin plugin version -
restart computer -
run android studio and now it works and it ran faster
tried
using local gradle repository
changing no proxy in setting-http
uninstalling, reinstalling, formatting my laptop
after 2 days:
i tried to see a kotlin in setting. then there was an update for kotlin,

Could not resolve com.android.support:appcompat-v7:26.1.0 in Android Studio new project

I know about this questions:
Failed to resolve: com.android.support:cardview-v7:26.0.0 android
Could not resolve com.android.support:appcompat-v7:26.1.0 [duplicate]
And I've read this documentations:
Migrate to Android Plugin for Gradle 3.0.0
Migrating to Android 8.0
So I'm posting this question believing its not a duplicate.
I've installed Android Studio 3.0.1. I didn't have any previous version before and I started a new project.
Every setting in Gradle file have been set by Android Studio itself and I've checked them all.
These are the file contents:
build.gradle (Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.administrator.as301test"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Top level build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
I use google() in repositories as here clearly says:
// If you're using a version of Gradle lower than 4.1, you must instead use:
// maven {
// url 'https://maven.google.com'
// }
My gradle version is 4.1 so I don't need above code.
But I still get this error as the others have been asking about:
Error:Unable to resolve dependency for ':app#debug/compileClasspath':
Could not resolve com.android.support:appcompat-v7:26.1.0.
Why should I get this error when I'm creating a new project in AS 3.0.1 and it has been set all the necessary settings?
Update
#Rohit's answer somehow solved the issue but I still get same error for some other dependencies.
Could not resolve com.android.support.test:runner:1.0.1
Could not resolve
com.android.support.test.espresso:espresso-core:3.0.1
Could not resolve junit:junit:4.12
Finally I fixed the problem by modifying build.gradle like this:
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 26
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
}
I've removed these lines as these will produce more errors:
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
Also I had same problem with migrating an existing project from 2.3 to 3.0.1 and with modifying the project gradle files like this, I came up with a working solution:
build.gradle (module app)
android {
compileSdkVersion 27
buildToolsVersion "27.0.1"
defaultConfig {
applicationId "com.mobaleghan.tablighcalendar"
minSdkVersion 16
targetSdkVersion 27
}
dependencies {
implementation 'com.android.support:appcompat-v7:25.1.0'
implementation 'com.android.support:design:25.1.0'
implementation 'com.android.support:preference-v7:25.1.0'
implementation 'com.android.support:recyclerview-v7:25.1.0'
implementation 'com.android.support:support-annotations:25.1.0'
implementation 'com.android.support:support-v4:25.1.0'
implementation 'com.android.support:cardview-v7:25.1.0'
implementation 'com.google.android.apps.dashclock:dashclock-api:2.0.0'
}
Top level build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
goto Android->sdk->build-tools directory make sure you have all the versions required . if not , download them . after that
goto File-->Settigs-->Build,Execution,Depoyment-->Gradle
choose use default gradle wapper (recommended)
and untick Offline work
gradle build finishes successfully for once you can change the settings
If it dosent simply solve the problem
check this link to find an appropriate support library revision
https://developer.android.com/topic/libraries/support-library/revisions
Make sure that the compile sdk and target version same as the support library version.
It is recommended maintain network connection atleast for the first time build (Remember to rebuild your project after doing this)
try this :
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
targetSdkVersion 26
}
}
compile 'com.android.support:appcompat-v7:25.1.0'
It has worked for me
I tried all of the above and nothing worked for me.
Then I followed Gradle Settings > Build Execution, Deployment > Gradle > Android Studio and checked "Disable embedded Maven repository".
Did a build with this checked and the problem was solved.
Just go to
File\Settings\Gradle. Deselect the "Offline work" box. Now you can connect and
download any necessary or missing dependencies
Your android studio may be forgot to put :
buildToolsVersion "26.0.0"
you need 'buildTools' to develop related design and java file. And if there is no any buildTools are installed in Android->sdk->build-tools directory then download first.
well got this answer from another site and don't want to take any credit for this but this solution works like butter.
Go to File\Settings\Gradle. Deselect the "Offline work" box. Now you can connect and download any necessary or missing dependencies.
This work for me. In the android\app\build.gradle file you need to specify the following
compileSdkVersion 26
buildToolsVersion "26.0.1"
and then find this
compile "com.android.support:appcompat-v7"
and make sure it says
compile "com.android.support:appcompat-v7:26.0.1"
OK It's A Wrong Approach But If You Use it Like This :
compile "com.android.support:appcompat-v7:+"
Android Studio Will Use The Last Version It Has.
In My Case Was 26.0.0alpha-1.
You Can See The Used Version In External Libraries (In The Project View).
I Tried Everything But Couldn't Use Anything Above 26.0.0alpha-1, It Seems My IP Is Blocked By Google. Any Idea? Comment
In my case, this error occur when i tried to use gridView
I resolved it by removing this line from build.grade(Module) file
implementation 'com.android.support:gridlayout-v7:28.0.0-alpha3'
This issue seems to like the following.
How to resolve repository certificate error in Gradle build
Below steps may help:
1. Add certificate to keystore-
Import some certifications into Android Studio JDK cacerts from Android Studio’s cacerts.
Android Studio’s cacerts may be located in
{your-home-directory}/.AndroidStudio3.0/system/tasks/cacerts
I used the following import command.
$ keytool -importkeystore -v -srckeystore {src cacerts} -destkeystore {dest cacerts}
2. Add modified cacert path to gradle.properties-
systemProp.javax.net.ssl.trustStore={your-android-studio-directory}\\jre\\jre\\lib\\security\\cacerts
systemProp.javax.net.ssl.trustStorePassword=changeit
Ref : https://www.cresco.co.jp/blog/entry/2014//
Try to clear cache in android studio by
File-> Invalidate cache -> invalidate
after invalidating
build-> clean project
Then you can able to build the project
this work for me
compile 'com.android.support:appcompat-v7:26.0.0'
change 26.0.0 to 26.0.1
compile 'com.android.support:appcompat-v7:26.0.1'
this work for me. add configurations.all in app/build.gradle
android {
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:27.1.1'
}
}

google play service error

I got this below error
Error:(1, 1) A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.application']
> Gradle version 2.10 is required. Current version is 2.8. If using the gradle wrapper, try editing the distributionUrl in C:\Users\TARUN\Desktop\GingerBuds\gradle\wrapper\gradle-wrapper.properties to gradle-2.10-all.zip
Then I changed the above gradle path, Then following problem occurred,
I am getting this exception, while building my project . I rebuild and clean the project and updated google-play-services , then also i got error. can anyone please help me how to solve this.
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
java.io.FileNotFoundException: C:\Users\TARUN\Desktop\Gingerbuds\app\build\intermediates\exploded-aar\com.google.android.gms\play-services\8.4.0\jars\classes.jar (The system cannot find the path specified)
Build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.kitchenvilla.gingerbuds"
minSdkVersion 15
targetSdkVersion 23
versionCode 24
versionName "1.2.2"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
android {
useLibrary 'org.apache.http.legacy'
}
android {
publishNonDefault true
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:recyclerview-v7:23.0.0'
compile 'com.mcxiaoke.volley:library:1.0.15'
compile 'org.apmem.tools:layouts:1.10#aar'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
compile 'com.google.android.gms:play-services-maps:8.4.0'
compile 'com.google.android.gms:play-services:8.4.0'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.pkmmte.view:circularimageview:1.1'
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
}
This bug has been fixed according to Google dev blog: http://tools.android.com/tech-docs/new-build-system
2.0.0-alpha6 (2016/1/15)
Instant Run
Fix alpha5 reported issues :
- cannot build when importing play-services.
You should update android gradle tools version
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha6'
}
This exception is thrown during a failed attempt to open the file denoted by a specified Path-name.
You can use
compile 'com.google.android.gms:play-services:8.3.0'
Update your classpath
classpath 'com.android.tools.build:gradle:2.0.0-alpha2'
this will solve it
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.google.gms:google-services:2.0.0-alpha2'
}
and
compile 'com.google.android.gms:play-services:8.3.0'
update gradle version to alpha9 in project level gradle file
classpath 'com.android.tools.build:gradle:2.0.0-alpha9'
i tried to import admob ads to a new app i was making and i ran into this problem...... i found the solution the be the StartAppInApp file being located in the wrong spot or not being there..... my app needed the StartAppInApp-3.1.1.jar file to be located in the libs folder and when i looked at my app there was no libs folder located there at all .....
open your main app folder... then click app and you should have 3 folders.... src ... build.... and libs .....
in my case there was no libs folder..... so i created the libs folder and then went and copied the StartAppInApp-3.1.1.jar file from a different android project i had and i pasted it to the new libs folder i made in my current project... the error is now GONE!
i also made sure to include
compile files('libs/StartAppInApp-3.1.1.jar')
in the dependencies of my app gradle file
not sure if this is a solid answer but if anyone has this problem double check your StartAppInApp-3.1.1.jar location and version and check your gradle dependencies

Android Studio Unable to load class 'org.codehaus.groovy.runtime.typehandling.ShortTypeHandling'

I installed Android Studio and when I try to import a project from gradle this resolve error shows up:
Unable to load class
'org.codehaus.groovy.runtime.typehandling.ShortTypeHandling'.
I deleted the files in my Users .gradle folder and tried different gradle versions. I don't know how to fix this.
This page might help solve the problem. What they say is:
So we leveraged this version to add a new artifact, named
groovy-backports-compat23. This artifact shouldn’t be necessary for
most of you, but if you face an error like:
Caused by: java.lang.ClassNotFoundException:
org.codehaus.groovy.runtime.typehandling.ShortTypeHandling at
java.net.URLClassLoader$1.run(URLClassLoader.java:372)
in your project, then it means that a class has been compiled with
Groovy 2.3+ but that you are trying to use it with an older version of
Groovy. By adding this jar on classpath, you give a chance to your
program to run. This may be particularily interesting for Gradle users
that want to use a plugin built on Gradle 2+ on older versions of
Gradle and face this error. Adding the following line to their build
files should help:
buildscript {
// ...
dependencies {
classpath 'some plugin build on gradle 2'
classpath 'org.codehaus.groovy:groovy-backports-compat23:2.3.5'
} }
Note that for now, this jar only contains the ShortTypeHandlingClass.
Future versions may include more.
- See more at: http://glaforge.appspot.com/article/groovy-2-3-5-out-with-upward-compatibility#sthash.mv7Y8XQv.dpuf
I can fix this error message using these three methods.
use latest gradle version
use latest android SDK and tools.
use proguard-rules.pro
build.gradle (Project:xxxxx)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
allprojects {
repositories {
mavenCentral()
}
}
build.gradle (Module:app)
apply plugin: 'android'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
I had the same problem. I ran gradle from command line and that did work.
After that, I found File -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle. There "Use local gradle distribution" was active. Changed it to "Use default gradle wrapper (recommended)" and it worked.
I have had a same problem. And I have found a solution.
Cause
This problem is caused by android gradle plugin does not match for gradle version.
Solution
Edit build.gradle in project. gradle plugin version must be satisfied requirements for android studio.
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
And edit distrubutionUrl in gradle/wrapper/gradle-wrapper.properties. version of gradle must be satisfied requirements for gradle plugin.
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip
You can find version compatibilities between android studio, android gradle plugin and gradle in this page
https://stackoverflow.com/a/29695756/3675925

Android Studio and Gradle - build fails

I am building a small library project along wit a sample project to illustrate the use. I can't manage to run the sample in Android Studio. I have created the project from scratch. I am experienced with Eclipse but it's my first try at Android Studio & Gradle.
The error given:
Gradle: Execution failed for task ':demo:dexDebug'.
Running C:\DevTools\Android\android-studio\sdk\build-tools\android-4.2.2\dx.bat
failed. See output
I have the following folder structure:
- demo
- build
- libs
- android-support-v4.jar
- src
- main
- java
- res
- build.gradle
- library
- build
- libs
- android-support-v4.jar
- src
- main
- java
- res
- build.gradle
- build.gradle
- settings.gradle
Build.gradle at project root:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
Settings.gradle at project root:
include ':library', ':demo'
Build.gradle for the library module:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
Build.gradle for the sample module:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile project(':library')
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
Specifying compile files('libs/android-support-v4.jar') means that every library includes support v4. What you want to do is just specify that every library depends on it:
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
This will allow gradle to detect all dependencies and include this only once.
Note: You have to first use the SDK Manager and download and install two Maven repositories: "Android Support Repository" and "Google Repository".
I found the problem:
I removed that line from the sample gradle file.
compile files('libs/android-support-v4.jar')
However, I have no idea why this does not work (if I have 2 or 3 external libraries that all depend on the support library, how are we supposed to do, without touching their gradle files?
You should navigate to your libs folder in the IDE, right click on the jar and select to add the library to the project, it still needs to establish the dependency even though the jar appears to be there. Also look at your gradle built script to make sure the dependency appears there. If that still doesnt work just run a gradle clean on the project. Intellij documentation will give you more details on what clean does. see:
stackoverflow gradle build
This error could be encountered while migrating from Groovy to kotlin DSL as well and here are the steps to get rid of it:
If you are still in the process of migrating please complete the migration of gradle files first, use kts syntax and then sync gradle files.
Use this dependency inside your build.gradle(app level):
implementation("androidx.legacy:legacy-support-v4:1.0.0")
Remove id("kotlin-android-extensions") from plugins block inside build.gradle.kts (app level).
That's it! 3rd Point solved the issue for me but trying all the points should definitely fix the issue.
In my Case replace this line
classpath "com.android.tools.build:gradle:7.0.2"

Categories

Resources