Error:(18, 0) Gradle DSL method not found: 'android()' [duplicate] - java

This question already has an answer here:
Error:(19, 0) Gradle DSL method not found: 'android()' not solved
(1 answer)
Closed 7 years ago.
I have the problem:
Error:(19, 0) Gradle DSL method not found: 'android()'
-The project 'x' may be using a version of gradle thet does not contais the method
Open gradle wrapper file
-The build file may be missing a gradle plugin
Apply gradle plugin
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.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
android {
}
dependencies {
}
app.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"
compileOptions {
encoding "UTF-8"
}
defaultConfig {
applicationId "es.albertoramos.pfcalbertoramos"
minSdkVersion 15
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.2.1'
}
How fix this problem?

Delete this from build.gradle
android {
}
dependencies {
}

Related

Error:(29, 17) Failed to resolve: junit:junit:4.12 Android Studio 2.1.2

I'm using Android Studio 2.1.2 and it is giving error "Error:(29, 17) Failed to resolve: junit:junit:4.12" Similar error for any third party library. I have tried removing and adding the junit library from Project Settings but still it giving same error. I'm not sure whether this proxy issue? I have checked connection from Studio for maven link and it is showing successful. Following is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
defaultConfig {
applicationId "com.example.administrator.myapplication"
minSdkVersion 17
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.0.0'
}
Project Level build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
repositories {
jcenter()
mavenCentral()
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Please let me know if I'm missing something and how to resolve this.
After lot of efforts I was able to resolve this issue. Issue lies with the proxy settings, I have added following lines in gradle.properties file and gradle synced successfully with dependencies resolved
systemProp.http.proxyHost=x.x.x.x
systemProp.https.proxyPort=xxxx
systemProp.https.proxyHost=x.x.x.x
systemProp.http.proxyPort=xxxx

Use ZXing library on an Android Project

I'm trying to build a project with the ZXing library. I used the instructions in this post to integrate the library into my Android project and I believe I have done that successfully. However, when I try to build the entire project, there is an error in the Gradle build that refers to a dependency or something similar. However, I think I've already solved all the issues with dependencies.
The returned error in Gradle :
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:prepareDebugDependencies'.
The message is
Dependency QRR:android:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency.
Here is the full Gradle log using Stacktrace.
EDIT:
In this project, I used the full ZXing library, not the Embedded or the Minimal.
After the download of the full repo of ZXing here, I've added the android folder as a new Module of the project. I've added the dependency on the Gradle file. Then, I've dowloaded the core on the Maven repo, then I imported it as JAR Library. I've added the dependency in the android:build-gradle.
The app:build.gradle is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.mehdi.qrr"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile project(':android')
compile 'com.google.zxing:core:3.2.1'
}
repositories {
jcenter()
}
The Project:build-gradle is:
// 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.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
repositories {
mavenCentral()
maven {
url "http://dl.bintray.com/journeyapps/maven"
}
}
The android:build-gradle (Gradle file of the ZXing project):
apply plugin: 'com.android.application'
android {
signingConfigs {
}
compileSdkVersion 21
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "com.google.zxing.client.android"
minSdkVersion 15
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.zxing:core:3.2.1'
}

Gradle DSL method not found: 'compile()' error

I promise I have looked at all the answers provided.
1) I wanted to use DialogFragment and developers guide suggested to install Support libraries. I agree I did not go through and pick and choose and I asked it to install all 22 Android support libraries (Android support repository already looked installed).
2) Ensured that the project level build.gradle does not have any compile under dependencies. Only the Module: app level build.gradle has the compile.
3) When I attempted to add the compile "com.android.support:support-v4:18.0.+" to the app module build.gradle, it reds on me because the target sdk is 22. So, I go to change it to 18. No dice.
4) Same annoying error: Gradle DSL method not found: compile():The project may be using a version that does not contain the method: open Gradle wrapper.properties OR The build file may be missing a plugin : Apply Gradle plugin
5) I applied every possible plugin.
Any help would be greatly appreciated.
Project level 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.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
App level build.gradle:
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias '******'
keyPassword '*******'
storeFile file('********************')
storePassword '********'
}
}
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "project.sample.com.blatest"
minSdkVersion 8
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
<!-- begin snippet: js hide: false -->
<!-- language: lang-html -->
apply plugin: 'com.android.application'
android {
signingConfigs {
config {
keyAlias 'dialogkey'
keyPassword 'changeme'
storeFile file('C:/Users/ybxk021/.android/default.keyset')
storePassword 'blabla123'
}
}
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "project.sample.com.dialogtest"
minSdkVersion 8
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.2.0'
compile 'com.android.support:support-v4:22.2.0'
}
}

Android Studio - Failed to resolve library in gradle

I have tried to import multiple libary for project in android studio.But it always shows error like
For this, I tried multiple solution like sdk update , studio update , build.gradle update and so on.Eventhough, i could not get any result.anyone give solution please.
Herewith I mentioned my gradle sepcification too.
app - build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.abof.android"
minSdkVersion 17
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services:7.5.0'
compile files('libs/volley.jar')
compile 'com.android.support:appcompat-v7:22.2.0'
compile project(':libraries:facebookV2')
compile files('libs/httpcore-4.3-beta1.jar')
compile files('libs/httpmime-4.3.5.jar')
compile project(':libraries:gson-2.2.4')
compile project(':libraries:citruslibrary')
}
project - 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.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}

Compile time only dependency and ProGuard using Gradle

I am building an Android library with Gradle and I have a compile time only dependency.
I am using Gradle 0.9+ so if I do
android.libraryVariants.all { variant ->
variant.packageLibrary.exclude( 'libs/libA.jar' )
}
it works and libA.jar is not packaged in my final aar.
However, if I turn ProGuard to on, this does not work and libA.jar is getting packaged.
I have also excluded this jar from obfuscation by adding
-keep class com.libA.** { *; }
to my proguard-rules.txt but it doesn't make any difference.
I can see that the proguardRelease task gets executed before all the packageRelease tasks, however I am not really sure if I can do anything.
This is my whole build file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
android.libraryVariants.all { variant ->
variant.packageLibrary.exclude( 'libs/libA.jar' )
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:20.0.0'
}
Is there any way to compile against a jar but exclude it from the final package without having to turn ProGuard off?
I just recently came back to this and found a workaround, so I thought I would share:
I am now adding the 'libs' folder as a local repository, so my build file looks something like that (I have also updated the Gradle version):
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
}
}
apply plugin: 'com.android.library'
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
dependencies {
compile ':libA'
compile 'com.android.support:support-v4:20.0.0'
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
The dependency is resolved fine and is not packaged in the final aar.
Also, I am not including anything extra in the proguard file.

Categories