I am attempting to add a directory as a dependency in Android Studio(GameBaseUtils). I have seen other SO answers simply posting the correct gradle configuration for their particular issue, however I don't understand how I can adapt their answers to my situation.
Here is what I did:
Step one: File-> Import Module ->Navigate to directory and select it.
Step Two-: File-> Project Structure-> Modules-> Select my application->Dependencies->Add the module as a dependency to my project.
Now my code doesn't have any red lines indicating an error importing the module. However when I select build I get the following errors:
Gradle: package com.google.example.games.basegameutils does not exist
Gradle: cannot find symbol class BaseGameActivity
Gradle: cannot find symbol variable super
...
Here is the build.gradle file for my application
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
}
How can I correctly import this external library and can you please explain how and why your solution works?
so here is how I solved my problem:
instead of adding
dependencies {
compile files('libs/android-support-v4.jar')
compile project(':Module')
}
You have to write:
dependencies {
compile files('libs/android-support-v4.jar', '../Module')
}
the 2 dots say that the Module (or directory) can be found in 1 directory above the actual one. so if you want to access a module which is 2 directories above you just have to write: '../../ModuleName'
You have to add the modules manually to the build.gradle because Android Studio is still in development and doesn't have finished the UI for editing the Project Structure.
If this does not solve your problem try to make it like this: (I would recommend this method. This is how I actually do it)
Examplestructure:
Project
libraries (normal folder)
Module2
Module1
settings.gradle
include ':Module1', ':libraries:Module2'
build.gradle (Module1)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile project(':libraries:Module2')
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 11
}
}
build.gradle (Module2)
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 8
targetSdkVersion 11
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
This should work well now.
To make everything work 100% follow this steps:
delete .idea folder
delete all *.iml files
Restart Android Studio and press Import Project
Select the directory with your gradle project
Import project from external model > Gradle > next > finish
With this steps everything should work well. If there are any problems just tell me :)
Do not add modules through the Studio interface. Always make the changes directly in build.gradle and then reimport into Studio.
Also, update the plugin dependency to com.android.tools.build:gradle:0.4.+ to get the latest 0.4.* version.
Related
I am attempting to run my project in Android Studio but the error appears below:
I have followed many sources just to get this to run and have wound up here, but do not know what else to do.
How can I configure this project to run?
build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.1"
}
settings.gradle:
include ':app'
local.properties:
sdk.dir=C\:\\Users\\KJA\\AppData\\Local\\Android\\sdk
gradle.propertes:
# IDE (e.g. Android Studio) users:
# Settings specified in this file will override any Gradle settings
# configured through the IDE.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
I went ahead and downloaded the project from the link you provided: http://javapapers.com/android/android-chat-bubble/
Since this is an old tutorial, you simply need to upgrade the software, gradle, the android build tools and plugin.
Make sure you have the latest Gradle and Android Studio:
https://www.gradle.org/
http://tools.android.com/tech-docs/new-build-system/version-compatibility
build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
allprojects {
repositories {
jcenter()
}
}
app/build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
defaultConfig {
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName '1.0'
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.2.1'
}
Then run gradle:
gradle installDebug
In your top level build.gradle you seem to have the code
android {
compileSdkVersion 19
buildToolsVersion "19.1"
}
You can't have this code at the top level build.gradle because the android build plugin isn't loaded just yet. You can define the compile version and build tools version in the app level build.gradle.
For some unknown reason, Android Studio incorrectly adds the android()
method in the top-level build.gradle file.
Just delete the method and it works for me.
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
}
I have tried to manage this issue via below steps :
Delete android { ... } block in top level root gradle file
Look into
compileSdkVersion 22
buildToolsVersion "22.0.0"
lines of code in app/gradle file here only one of the version persent in below dropdown should be present else it would give provide option to downloaad the same.
I got this same error when I was trying to import an Eclipse NDK project into Android Studio. It turns out, for NDK support in Android Studio, you need to use a new gradle and android plugin (and gradle version 2.5+ for that matter). This plugin, requires changes in the module's build.gradle file. Specifically the "android{...}" object should be inside "model{...}" object like this:
apply plugin: 'com.android.model.application'
model {
android {
....
}
}
So if you have updated your gradle configuration to use the new gradle plugin, and the new android plugin, but didn't change the module's build.gradle syntax, you could get "Gradle DSL method not found: 'android()'" error.
I prepared a patch file here that has some further explanations in the comments:
https://gist.github.com/shumoapp/91d815de6e01f5921d1f
These are the changes I had to do after importing the native-audio ndk project into Android Studio.
Correcting gradle settings is quite difficult. If you don't know much about Gradle it requires you to learn alot. Instead you can do the following:
1) Start a new project in a new folder. Choose the same settings with your project with gradle problem but keep it simple: Choose an empty main activity.
2) Delete all the files in ...\NewProjectName\app\src\main folder
3) Copy all the files in ...\ProjectWithGradleProblem\app\src\main folder to ...\NewProjectName\app\src\main folder.
4) If you are using the Test project (\ProjectWithGradleProblem\app\src\AndroidTest) you can do the same for that too.
this method works fine if your Gradle installation is healthy. If you just installed Android studio and did not modify it, the Gradle installation should be fine.
Actually i tried many combinations nothing worked
but when i modified my application gradle file with following
buildTypes {
release {
minifyEnabled false
}
}
By removing the Line
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
it worked Normally :)) cheers
Another solution if you have installed android-studio-bundle-143.2915827-windows
and gradle2.14
You can verify in
C:\Program Files\Android\Android Studio\gradle if you have gradle-2.14.
Then you must go to
C:\Users\\AndroidStudioProjects\android_app\
And in this build.gradle you put this code:
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()
}
}
Then, go to C:\Users\Raul\AndroidStudioProjects\android_app\Desnutricion_infantil\app
And in this build.gradle you put:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '24.0.0'
defaultConfig {
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.3.0'
}
You must check your sdk version and the buildTools.
compileSdkVersion 23
buildToolsVersion '24.0.0'
Save all changes and restart AndroidStudio and all should be fine !
Just delete these lines from the root build.gradle
android {
compileSdkVersion 19
buildToolsVersion '19.1' }
Now trying and compile again. It should work.
Change to root build.gradle file
to
// 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
}
What worked for me was to import the project with "File -> New -> Project from Version Control" then choose your online source (GitHub for example). This way all the .gradle files were created in the import.
I also meet that problems,and just delete bottom code:
DELETE THESE LINES:
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
}
it worked。
This error has occurred when i was importing a project from Github. This happens as the project was of older version. Just try to delete these methods below from your root gradle.
android {
compileSdkVersion 19
buildToolsVersion "19.1"
}
then try again.
I hope it works.
I found an open source project I wanted to work on but I'm having trouble setting up the initial configuration. The project seems to have been written in Eclipse and I'm trying to get it to work with Android Studio. After being through a number of errors, I'm finally stuck on the following error seen in the configuration menu before I run.
AndroidManifest.XML doesn't exist or has the incorrect root tag
I found a number of answers that suggest like this that suggest I use the sync project with Gradle command but my project wasn't setup with Gradle because I'm building on someone else's project. This is my first time using Android Studio so my following attempt to fix this might not be great. I decided to try to make the project a Gradle project by adding my own build.gradle and settings.gradle files. My layout looks like this:
top level:
inside java folder:
I tried to copy working example of the build and settings Gradle files. My settings.gradle contains the following:
include ':'
My top level build.gradle contains:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
//compile project(":")
}
}
allprojects {
repositories {
mavenCentral()
}
}
My java level build.gradle contains:
apply plugin: 'android'
android {
compileSdkVersion 20
buildToolsVersion "17.0.0"
defaultConfig {
applicationId "org.pocketworkstation.pckeyboard"
minSdkVersion 8
targetSdkVersion 19
versionCode 1037
versionName "v1.37"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
jni.srcDirs = ['jni']
}
androidTest.setRoot('tests')
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
And because I think it might be important, my project structure modules:
Trying to synchronize at the moment doesn't generate any word so I assume it's okay but that's a big assumption. Any ideas what I have to change?
Android Studio doesn't consider your project to be a Gradle-based project; you can tell this because a number of the entries you're seeing in the Project Structure dialog don't show up for Gradle-based projects (i.e. the Project, Libraries, Facets, and Artifacts) entries. Close your project and re-import it as a Gradle-based project and you should be okay.
In the 3rd answer here:
How do I add a library project to Android Studio?
I found informations about how we can add ABSherlock library to project using gradle in Android Studio. But in this way we use "import module" option which doesn't exist any more in Android Studio 0.4.0. So how should I add ABSherlock or other library now ? (using gradle)
You can add this part to your build.gradle script
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
}
EDIT:
If you are using also the support library you can use it:
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile ('com.actionbarsherlock:actionbarsherlock:4.4.0#aar'){
// Need to specifically exclude this as it is specified in ActionBarSherlock pom
exclude group: 'com.google.android', module: 'support-v4'
}
}
EDIT2:
If you would like to work with abs with a local copy ( I suggest you to use the maven dependency ) you can do this:
-root
-lib
-abs
build.gradle
src
res
-myModule
build.gradle
settings.gradle
In settings.gradle:
include ':myModule', ':lib:abs'
In lib/abs/build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion XX
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.0'
}
Remove the supportV4.jar from your local abs library.
In myModule/build.gradle you should add:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion XX
targetSdkVersion 19
}
}
dependencies {
// Libraries
compile project(':lib:abs')
}
If in myModule/build.gradle you need to use the support library, you should add:
dependencies {
compile 'com.android.support:support-v4:19.0.0'
// Libraries
compile project(':lib:abs')
}
Working with gradle you should prefer to use dependencies in Maven.
However you can use local libraries with this structure above, editing your gradle files.
I've never used Gradle before so I'm completely lost!
I've added SlidingMenu as a library and I have access from my project to all the SlindingMenu stuff, but trying to compile will give me this error:
Gradle: package com.jeremyfeinstein.slidingmenu.lib does not exist
I'm using Android Studio (so IntelliJ) and this is my gradle.build
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
}
Thanks in advance
Assuming you have added SlidingMenu.jar into libs folder, right click on it -> Add as library. Then change in gradle.build:
Before:
dependencies {
compile files('libs/android-support-v4.jar')
}
After:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
This will include all your jar files.
I had the same problem. Adding sliding-menu-lib from with gradle-build as android library did help me.
My project structure is as:
-MyDemoProject
-build.gradle
-settings.gradle
--MyDemo
--build.gradle
--libs
---sliding-menu-lib
----res
----src
----AndroidManifest.xml
----build.gradle
--src
To make all the stuff working your settings.bundle should have this contents:
include ':MyDemo' ':MyDemo:libs:sliding-menu-lib'
There is a trick here, which allows you avoid errors while building project with gradle using Android Studio, as according to Android Tools Manual you should use ':libs:sliding-menu-lib' but that does not work due to issue with relative projectDir paths.
Your MyDemo/build.gradle should contain dependencies like:
dependencies {
compile 'com.android.support:support-v4:18.0.0'
...
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':MyDemo:libs:sliding-menu-lib')
}
And your sliding-menu-lib/build.gradle should be like:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 14
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 14
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
Most important part deals with sourceSets section as you may not want change sliding-menu-lib file structure (non-default for current gradle)
I added all of my previous libraries using the default import from source tool. For SlidingMenu I used the import with Maven then deleted all of the Maven dependancies from the Project Settings for SlidingMenu and reimported the Support libraries. This seemed to clear most issues up for me.
If the module is just a library and not a stand-alone app, it's gradle should contain
apply plugin: 'android-library'
instead of
apply plugin: 'android'
You can Sync Project with Gradle Files:
Tools -> Android -> Sync Project with Gradle Files
Recently found better solution for SlidingMenu separately:
You can add SlidingMenu as generated #aar file if you do not need to make any changes to it. Just use https://github.com/jzaccone/SlidingMenu-aar and make changes as in Readme file there.
Be careful with order of repos. This one should be above mavenCentral()
After changes to source and building with gradle in Android Studio (I/O preview) AI - 130.677228 the build fails with the following error:
Gradle:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileDebugAidl'.
> No signature of method: com.android.ide.common.internal.WaitableExecutor.waitForTasks() is applicable for argument types: () values: []
Possible solutions: waitForAllTasks()
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Could not execute build using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
The second time running a build the build will succeed.
Using a gradle wrapper with version 1.6
This really sucks because it does a long build (non-incremental) after it fails the first time.
Is there a way to not have this failure?
EDIT to include build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
task wrapper(type: Wrapper) {
gradleVersion = '1.6'
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion "Google Inc.:Google APIs:17"
buildToolsVersion "17"
defaultConfig {
minSdkVersion 11
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
Link to issue on Google Code: https://code.google.com/p/android/issues/detail?id=56158
I solved this issue by setting buildToolsVersion in my build.gradle file to match the latest version of the Android SDK Build-tools in the SDK manager.
In my case, I have the Android SDK Build-tools version 22.0.1 installed, so I set buildToolsVersion accordingly:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
...
After making that change, my app builds uneventfully.
I'm not sure how this is possible. It looks like you have a mismatch between the Gradle plugin itself and its dependencies that provides the WaitableExecutor class.
However you mention Gradle 1.5 and this is a problem.
The plugin version 0.3 was compatible with Gradle 1.3-1.4
The new version release last week, 0.4 is compatible with Gradle 1.6+
Make sure you use 0.4 and the new Gradle version.
I was facing the same issue "Failed to execute the task: compileDebugaidl aidl/debug/".
I saw further in Gradle Console for the specifics and it read as below:
Failed to capture snapshot of output files for task 'prepareComAndroidSupportAppcompatV72103Library' during up-to-date check.
Could not remove entry '/Users/..../.../.../..../build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.3' from cache outputFileStates.bin (/Users/..../..../..../.gradle/2.2.1/taskArtifacts/outputFileStates.bin).
I resolved it by deleting the outputFileStates.bin file from the terminal and allowed Gradle to recreate it.
Hope it helps somebody.
Add:
compileSdkVersion 17 to your buid.gradel file (below).
And use version 3 of the plugin: com.android.tools.build:gradle:0.3 (or higher for future questions,etc)
Edit: reference project I just created. Builds, signs,etc https://github.com/yegdroid/gradle_demo
//
// A basic Android application that follows all the conventions
//
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.3'
}
}
apply plugin: 'android'
android {
testBuildType = "debug"
defaultConfig {
versionCode = 1
versionName = "0.1"
minSdkVersion = 9
targetSdkVersion = 17
compileSdkVersion 17
buildConfig "private final static boolean DEFAULT = true;", \
"private final static String FOO = \"foo\";"
}
buildTypes {
debug {
packageNameSuffix = ".debug"
buildConfig "private final static boolean DEBUG2 = false;"
}
}
aaptOptions {
noCompress "txt"
}
sourceSets {
main {
manifest {
srcFile 'AndroidManifest.xml'
}
java {
srcDir 'src'
}
res {
srcDir 'res'
}
assets {
srcDir 'assets'
}
resources {
srcDir 'src'
}
}
}
}
Add the code below into your build.gradle file. This works for me.
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
Please, try checking "Use default gradle wrapper" option in the Project-level settings.
Android Studio --> File --> Settings --> Build, Execution, Deployment --> Build Tools --> Gradle
Like to register my problem and solution here since it is almost relevent to the issue posted that if someone stumbles across the error could overcome it quickly.
I faced a similar issue with Failed to execute the task: compileDebugaidl aidl/debug/.. Access is denied ...
I overcame the issue by deleting the build directory and rebuilding it again[I'm using the Gradle 0.14.4]
This works for me
edit in your project build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
//delete this line below
classpath 'com.android.tools.build:gradle:1.0.1'
//add this line below
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
The missing AIDL something is google android studio problem to not update major gradle dependencies class path.
Fix:
- open project gradle file (no app, project !)
- replace:
classpath 'com.android.tools.build:gradle:1.0.1' or whatever
with
classpath 'com.android.tools.build:gradle:1.3.1'
If you can not compile a time before, compilable project, the google cat & dog are not sleeping and theire making changes, updates, therefore you have to wake up and made changes where they forget to.
And gradle is quite unstable project and buggy.
Can i see gradle (error filtered) output? (toolwindow gradle, gradle tab)
Looks like there is problem with functions inside the aidl files, which are mostly for outside application interface, & services.
Etc to transfer data to widget, or if you need data transfer between two applications.
Second posibility is two libraries with the same aidl structure, just one function is differrent, than one, or you are using the same library twice.
Another reason i newer saw with this message