I needed to add a android.support.v4.widget.NestedScrollView to my project, which requires the V4 support library according to this question.
In the answer it said . . .
You need to add this line in dependencies:
compile 'com.android.support:support-v4:23.4.0'
...I assumed that referred to the build.gradle file. I have two - a top-level one and a module one. Only my top-level one had a dependencies keyword, so I put it there. But when I did I got
Error:(8, 0) Gradle DSL method not found: 'compile()'
...which is addressed in this question here as well as this question where it indicates I need to move it to the build.gradle for my module. But the module build.gradle has a completely different structure so I don't know where it goes.
My top-level build.gradle looks like this:
// 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:2.1.2'
compile 'com.android.support:support-v4:23.4.0'
}
}
allprojects {
repositories {
jcenter()
}
}
And my module-level one looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 16
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.assemblyguide.remote"
minSdkVersion 16
targetSdkVersion 16
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
Where do I put the compile statement (or the dependencies clause it goes into) in the module build.gradle to avoid that error, and why do the two build.gradle files look so completely different?
Bonus question: I'm new to Android Studio and I didn't have to know this stuff for Eclipse. How much of a Gradle expert should I plan to be to use Android Studio and where can I get a basic understanding of Gradle without having to get a PhD in it?
I suggest you download the full Gradle distribution, which comes with the "User Guide" PDF. Read it from top to bottom, skipping chapters that are truly not relevant to you. You'll avoid having to ask many questions.
Direct link to Gradle User Manual pdf
In your case, you should remove the "compile" line you added in the "buildscript" block. You likely need to replace your "allprojects" block with the following:
allprojects {
repositories {
jcenter()
}
dependencies {
compile 'com.android.support:support-v4:23.4.0'
}
}
You should declare the the dependencies at the end of your main project module. Usually it is the app module. Find a build.gradle file there and follow the instructions shown here
It should look like this one
Related
First of all, I know there are a lot of subjects about this problems, but I still can't fix it.
I'm just trying to customize aviary sdk by following the guide here : https://developers.aviary.com/docs/android/setup-guide# (section 4.2, not 4.1)
here are my root gradle files :
build.gradle
buildscript {
repositories {
jcenter()
}
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
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
settings.gradle :
include ':app', ':Aviary-Android-Sample-App'
here is my app build.gradle file :
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.agaze.myapplication"
minSdkVersion 10
targetSdkVersion 20
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:20.0.0'
compile project(':Aviary-Android-Sample-App')
}
Here my files tree:
Thanks in advance for your tips.
Antonin
Check your submodules and make sure each submodule in your project has its own build.gradle file.
Check this guide for more info
tools.android.com/tech-docs/new-build-system/user-guide
Each library you add to your project should have it's own build.gradle file. If it does not have you can get this error.
For a solution you can add your sdk as a module with Android Studio. To do this you can follow the path in Android Studio:
File > New > Import Module and select directory of your sdk and add to your project.
Select Gradle System and let Android Studio create gradle files for your sdk.
You can check the link below for more information and how to add a module to your project.
http://www.truiton.com/2015/02/android-studio-add-library-project/
I hope this'll help you.
From your screen shot.It's obvious that the Aviary-Android-Sample-App is an eclipse project(no gradle file there) but not a valid gradle module.
If you want to import it into android studio, in android studio, click File -> new module -import eclipse adt project and go on under the instruction.
And you are good to go.
Edit:
Also, it seems that you want to modified the Aviary sdk, but the module you want to import is a sample app. Maybe you have downloaded the wrong file. The correct link looks like this one https://creativesdk.adobe.com/downloads.html
I have followed everything according to document provided by google, but am facing some issues, I have added google-services.json in root directory i.e in app.
Error:
Execution failed for task ':app:processDebugGoogleServices'.
No matching client found for package name 'com.google.samples.quickstart.analytics'
am getting this error. do help am working on android studio.
Try resolving the issue by adding the following line in the dependencies of the project-level build.gradle:
classpath 'com.google.gms:google-services:1.5.0'
Now Use like this in build.gradle:
com.google.android.gms:play-services-analytics:8.4.0
And follow this instructions:
Add Analytics to Your Android App
You can also generate configuration file from there
Follow the title: Add the configuration file to your project
Hope it will helpful for you.
EDIT:
Also please check if your build.gradle contains this line then remove it:
apply plugin: 'com.google.gms.google-services'
Seriously, Google should really make GA easier for all of us!!
Here's how I manage to get it work on buildToolsVersion '23.0.3' with com.google.android.gms:play-services:8.4.0
app build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
applicationId 'com.xxx.xxx'
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName '1.0'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
res.srcDirs =
[
'src/main/res/layouts/account',
'src/main/res/layouts/drawer',
'src/main/res/layouts/ntd',
'src/main/res/layouts/main',
'src/main/res/layouts',
'src/main/res'
]
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.google.android.gms:play-services:8.4.0'
}
I actually remove this line compile 'com.google.android.gms:play-services-analytics:8.4.0' and it still works.
top-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:2.0.0'
classpath 'com.google.gms:google-services:2.0.0-alpha6'
// 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
}
GAV4 is really a pain in the axx, so I would also like to remind you somethings.
google-services.json
Official GAV4 Document tells you to generate google-services.json and put it under your project/app/ folder. However, it never says anything about this message.
AnalyticsService not registered in the app manifest. Hits might not be
delivered reliably. See google short url for instructions.
And I end up find the solution here analyticsservice-not-registered-in-the-app-manifest-error
json with flavor
If you are building a complex project, you might also want to use flavor for different json files. See the flavor config here google-services-json-for-different-productflavors?lq=1
xml app tracker
Yet, you would still have a hard time using xml to configure the tracker, so I also advice you to see this thread google-analytics-v4-string-xml-configuration-name-not-recognized-ga-trackingi
google_app_id
Finally, you would still see this message
GoogleService failed to initialize, status: 10, Missing an expected
resource: 'R.string.google_app_id' for initializing Google services.
Possible causes are missing google-services.json or
com.google.gms.google-services gradle plugin.
which you could find some discussion here googleservice-failed-to-initialize
In strings.xml, I do add R.string.google_app_id which is your project id in google api console, but I think it would still work even without it. I just want to get rid of that message from the log.
Wish you all good luck!
i have a hello world full screen android studio 1.5.1 app that i added a gradle/eclipse-mars subproject to. no other files were modified except for adding include ':javalib' to settings.gradle. adding a project lib dependency:
project(':app') {
dependencies {
compile project(':javalib') // line 23
}
}
to the root build build file and running gradle from the command line , gets:
Where:
Build file 'D:\AndroidStudioProjects\AndroidMain\build.gradle' line: 23
What went wrong:
A problem occurred evaluating root project 'AndroidMain'.
Could not find method compile() for arguments [project ':javalib'] on org.grad
le.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated#46
3ca82f.
adding the java plugin to the root build file did not help.
i don't think it's in the wrong place.
both the root project and the added subproject have the gradle wrapper.
any pointers will be appreciated.
thanks
edit: for clarification, the root build file 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 hello << { task -> println "I'm $task.project.name" }
}
project(':app') {
dependencies {
//compile project(':javalib') // causes problems
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and the app build file is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "acme.androidmain"
minSdkVersion 22
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 project(':javalib') // use :javalib:jar?
//testCompile project(':javalib')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
}
edit: the whole purpose of this exercise is to get core java code into an android project. currently the core code is a standalone gradle/eclispe project. i have a batch in the android project that does a gradle -p standaloneprojectdir/ jar and copied the jar into libs/.
i just though there would be an easier way other than to publish the jar and get it from a repository since this all done on my pc.
it would be nice to have all the code live and just do a build :(
edit: as per RaGe's suggestion, here is a virgin android studio project and a virgin gradle/eclipse project. no editing has been done to these files. you mission should you choose to accept it is to get the android app to easily access the java project classes (i.e. new Library(); in MainActivity.onCreate() will compile and run). i don't care where the java project lives. ideally, both sources would be live in both ide's.
atempting this fails also. says: > Could not find :virginjavaproject, but directory does exist.
edit: what actually worked was RaGe's pull request to the virgin android project.
You already have
compile project(':javalib')
in your :app project, you don't have to also inject the dependency from your root build.gradle. If you still want to do it from the root build.gradle, the correct way to do it is:
configure(':app') {
dependencies {
compile project(':javalib') // causes problems - NOT ANYMORE!
}
}
the virgin android studio head is what worked.
We have 2 files named "build.gradle".
make sure you have copied your "compile code" in the build.gradle file that is inside "app" folder
As stated by #peter-niederwieser:
The build script is mixing up buildscript dependencies (i.e. dependencies of the build itself; typically this means Gradle plugins) with regular dependencies (i.e. dependencies of the code to be compiled/run). The latter need to go into dependencies { ... }, not into buildscript { dependencies { ... } }. Everything but the classpath dependencies are regular dependencies.
Also have a look at this: Could not find method compile() for arguments Gradle.
Simply paste this on build.gradle(Project:"Your prject name")
// 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:2.1.2'
// 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
}
I had this problem but with my own library. The way to correctly compile was:
compile project(path: ':MyLib')
I am getting the following build error when I try and sync my project:
Error:(9, 0) Gradle DSL method not found: 'compile()'
Possible causes:The project 'AlexTest' may be using a version of Gradle that does not contain the method.
The build file may be missing a Gradle plugin.
link: Apply Gradle plugin
I have tried applying every single gradle plugin they link me to in that link on the bottom, yet same issue, so I conclude that the first error is the cause.
Here is the build.gradle file for AlexTest (the project directory):
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.2'
compile 'com.google.android.gms:play-services:6.1.11'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
I think that was the gradle file it was having trouble with. But I'm not sure what method it is referring to.
Also here is the gradle-wrapper.properties which it also referred to:
#Mon Nov 10 01:06:12 PST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip
perhaps the gradle version in the distributionUrl needs to match the one in the dependency?
I also have a build.gradle file in the app directory itself - 1 level lower, though I don't think that is what it was referring to, but here it is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.snappiesticker.alextest"
minSdkVersion 16
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:6.1.+'
}
I have tried applying every single gradle plugin they link me to in that link on the bottom, yet same issue, so I conclude that the first error is the cause.
Correct.
Here is the build.gradle file for AlexTest (the project directory):
You will notice that this file contains a code comment:
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Remove the compile 'com.google.android.gms:play-services:6.1.11' line from that file. Leave the compile 'com.google.android.gms:play-services:6.1.+' that you have in the other build.gradle file.
The dependencies closure in buildscript is for Gradle plugins only. The top-level dependencies closure, found in the module's build.gradle file, is for application dependencies.
Saw reports that the problem occurred for other reasons, but this solved for me.
If you carry out any changes in the Project Structure (Android Studio) and press OK, Gradle will be synchronized, but this type of synchronization, if the dependency block has something like:
This block will stay this way after synchronization:
One way to solve the problem is to insert a line break to stay as it was before the synchronization or put a semi-colon between the two statements.
I hope it helps.
Just add foolwoing statement in your dependencies
apply plugin: 'jetty'
Hi everyone for me it was a "couple days consuming job" to make my app run in Android Studio (I migrated from Eclipse and had this problem too ) . Finally I found that very simple way of it .
Create libs folder under src/main/java/ it is App/java/libs in left pane .
Copy and paste all your external jars into here.
Goto left pane and right click on your App then click Open Module Settings
Then Project Structure window will appear .
Then move to Dependencies tab .
Final Step : Add all your jars located in App/java/libs (You will find them in src/main/java/libs) one by one .
That is all Enjoy it.
Declare dependencies in Module's build.gradle file, not in AlexTest's build.gradle file
I'm building an Android app in which I want to use the ActiveAndroid ORM. In the readme I read instructions on how to include it in Maven or ADT, but I'm using/trying to learn Android Studio with Gradle. So I guess I need to insert ActiveAndroid as a dependency. in my build.gradle file on these lines:
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
I don't really know what kind of string/url I should use so that Gradle can automatically find ActiveAndroid and compile it into my project.
Sicne I'm kinda lost; could anybody give me a tip here on how I should be tackling this?
[EDIT]
I now build the jar and compiled it using the suggested compile files('libs/ActiveAndroid.jar') (I have no version name in my jar file). It now builds successfully, but I still cannot import classes from it. See the image below:
Give this a go - download the JAR from here
Add it to your libs folder.
Change your dependancies to look something like this
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile files('libs/ActiveAndroid-3.3.jar')
}
Maybe this is new since this question was answered, but this is in the getting started guide:
Modify your build.gradle to include:
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
https://github.com/pardom/ActiveAndroid/wiki/Getting-started
Download the JAR from this link
OR
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
I can't answer the comment since I don't have enough rep yet, but make sure you sync your project with your gradle files again after adding the .jar to your dependencies.
Tools > Android > Sync Project with Gradle Files
Please make sure dependencies are added in individual module build.gradle file and NOT the common build.gradle file?
Also, under "Open Module Settings" make sure the dependencies are present under the "dependencies" tab of the app.
After you add the jar file to "libs" folder, build again and check if there is a build.gradle for ActiveAndroid module.This is what it should look like or a variation of this:
configurations.create("default")
def jarFile = file('ActiveAndroid.jar')
artifacts.add("default", jarFile)
Bit of an old question but having just run into this issue as I'm getting up to speed with both Android Studio/Gradle and AndroidActive, the documentation tells you what you need to add, but expects you to know how to add it. Basically in the build.gradle for the app (not the project). Add the repositories at the top of the file (if it doesn't exist already) and add the compile statement to the end of the dependencies section. I've attached screen shot of my Gradle file that worked.
My full build.gradle(app) with ActiveAndroid:
buildscript {
repositories {
mavenCentral()
}
dependencies {
}
}
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
apply plugin: 'com.android.application'
dependencies {
compile 'com.michaelpardo:activeandroid:+'
// other dependencies
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 24
buildToolsVersion '24.0.0'
defaultConfig {
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName '1'
multiDexEnabled true
}
}
Try these steps:
Go to this link - https://oss.sonatype.org/
Search for michaelpardo
A list which also include activeandroid would have came up
Click on the specific row and download the jar file
Put that jar file in libs folder and use Add to library option from Android Studio
Compile and it should work