Gradle DSL method not found:android() - android

Error:(1, 0) Gradle DSL method not found: 'android()'
Possible causes:
The project 'MyApp1' may be using a version of Gradle that does not contain the method.
Gradle settingsThe build file may be missing a Gradle plugin.
Apply Gradle plugin
Root/build.gradle
android {
compileSdkVersion 21
buildToolsVersion '21.1.1'
defaultConfig {
applicationId "com.example.shark.gpsapp"
minSdkVersion 15
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.android.support:appcompat-v7:22.2.0'
}
App/build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "23.0.0 rc3"
defaultConfig {
applicationId "com.example.shark.myapp"
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:22.2.1'
}
I coudln't open any of my old projects.Please do suggest a answer.
I got this error after android studio update.

You cannot call android until after you apply the android plugin com.android.tools.build:gradle.
The gradle build file uses a DSL based on Groovy, a Java-like dynamic language. android { ... } is a call to a method named android, passing the block. The message you are getting indicates that the method android has not been defined. It is defined in the plugin.
Somehow, your root level build.gradle file is a near duplicate of your app level build.gradle. It should not be so.
I suggest that you create a completely new project, using Android Studio, and copy it's root level build.grade file to the existing project.

Related

Importing JoystickView into Android Studio

I'm trying to import this custom view: https://github.com/zerokol/JoystickView into Android Studio by following these instructions: Importing a custom view in Android Studio.
So I go File -> New -> Import Module, leave everything as default and import.
I then get this error:
I clicked the link and updated everything to the latest versions but it still doesn't work.
build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "jacobpihl.bluetoothcar"
minSdkVersion 15
targetSdkVersion 23
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:23.1.0'
}
As it doesn't have any resources, you can just copy the class and put where you want in your project.

Android Studio telling me it cannot resolve symbols?

Android Studio was telling me it couldn't resolve some symbols in my code. After research, it was apparent that my project was API level 23, which wasnt compatible with some of the code. I decided to change it to API level 21.
Below is the previous code in my build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.scriptdesigninc.test_app"
minSdkVersion 8
targetSdkVersion 23
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:23.0.1'
}
I was told that I have to change it to the following,
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.scriptdesigninc.test_app"
minSdkVersion 14
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:22.2.0'
}
After I changed it, it told me I am missing the API package and that I have to download it, which I did. Then I clicked "retry" and it said it was unable to sync gradle project.
Please help, thank you in advance.
dependencies {
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
}
Add the above dependency in your build.gradle file.
This is happening because Android M does not supports the Apache HTTP API

Add Dependency to module - External Library Error

I've created an external library that I was hoping to make open source. I import it as a module without issue.
I have to resolve this issue after import:
Adding the dependency is what I want to do. I don't want to move it to :app.
When I add the dependency, the issue goes away. The import references the correct file. On build I get this issue:
I figure the solution has to be with referencing the java file in the build.gradle file for the external library but I couldnt find any good examples or even proof that this would resolve the issue.
library is the module name.
Thanks in advance.
Edit:
build.gradle for the app
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"
defaultConfig {
applicationId "com.weaverprojects.toundertest1"
minSdkVersion 21
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.google.android.gms:play-services-gcm:7.5.0'
}
build.gradle for library
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"
defaultConfig {
minSdkVersion 19
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'
compile 'com.google.android.gms:play-services-gcm:7.5.0'
}
Settings.gradle
include ':app', ':library'
Assuming that your library exists as it's own project, and it'd path relative to the top level folder for your main project is ../mylibs/library/ I think your settings.gradle should change as follows:
project(':library').projectDir = new File('../mylibs/library/');
and the following needs to go inside the dependencies section of your main/app/build.gradle file (which I think is the first code dump in your question).
compile project(':library')
BTW, please consider renaming :library to something else (this is not the source of the problem but the name can be confusing when you look at it some months later)

Not able to communicate between two modules in an Android project?

My project have two modules:
App
Facebook-lib
Here are my gradle files:
setting.gradle
include ':app', ':facebook-lib'
Module App gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.app.test"
minSdkVersion 18
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.1.1'
compile project (':facebook-lib')
}
Module Facebook-lib gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 18
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.1.1'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
}
Whenver I am trying to access Facebook-lib class in App module. It works but I can't do vice versa.
I get com.app.testpackage doesn't exist or cannot find symbol class.
What I am doing wrong here?
You can't achieve it.
Your Module App has a dependency with the Module Facebook library. It means that you can use the classes inside the library in your main module.
Your Facebook library doesn't have a dependency with your module. It means that you can't use the classes in main module.
Also you can't create a circular dependency.

Include apk module as dependency in android studio

I have two modules in my project:
app
app_list
Both modules have java and res. app_list has some activities that I want to launch in app.
In Eclipse, I had app_list as dependency library and I was able to launch activity of app_list. In Android Studio, when I added app_list as dependency, it says:
"Error:A problem occurred configuring project ':app'.
> Dependency NewMathBuzz:app_list:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency. File: <home>/NewMathBuzz/app_list/build/outputs/apk/app_list-release-unsigned.apk
"
app > build.gradle is as below:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.mass.mathbuzz"
minSdkVersion 7
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile project(':app_list')
compile fileTree(dir: 'libs', include: ['*.jar'])
}
app_list > build.gradle is as below:
apply plugin: 'com.android.library'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 7
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.mcxiaoke.volley:library:1.0.18'
compile 'com.android.support:appcompat-v7:22.0.0'
}
Could someone help me with this?
Everything was fine,
basically when I changed app_list.gradle as
apply plugin: 'com.android.application' to apply plugin: 'com.android.library' and deleted applicationId from app_list.gradle
it compiled and generated apk but I was getting runtime error that was because both app and app_list both had same resource main_activity so R.java didn't have main_activity res of app_list so it was giving illegal_parameter error . When I changed name of main_activity to some unique name it solved the issue

Categories

Resources