I tried to add the support library v4 in a project with android studio, I read how to add the support library
Add support library to Android Studio project
but the tab dependencies not appear. I click on the (only) module of my project, but do not appear. I tried with a blank project nothing appear.
EDIT
Project structure dialog
project
EDIT 2
The build.grade file as generated by Android Studio
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 16
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
}
dependencies {
}
First I recommend you to upgrade the AS to 0.4.0, lot of bugs are fixed in this.
Then check for the dependencies in build.gradle of your MyApplication module for support library.
dependencies {
compile 'com.android.support:support-v4:18.0.+'
}
If not added add the mentioned dependency.
After adding the line sync project with Gradle Files using the option available in toolbar.
Make sure you are not getting any error. If sync happens successfully check the Module again.
You should see screen like this, In my case support v7 also added, you can ignore that.
Related
I'm trying to use RomainGuy's ViewServer (https://github.com/romainguy/ViewServer) with my Android Studio project using Gradle, and I can't get it to work.
My understanding is to add a folder in project root ('libraries'), drop the ViewServer directory into it (not the full ViewServer directory but the actual library viewserver folder within ViewServer, and reference it in settings.gradle
include ':VendorSearch'
include ':libraries:ViewServer'
and also in my build.gradle file
compile project(":libraries:ViewServer")
When I do this I get a message that says
Could not find any version that matches com.android.tools.build.gradle:0.5.+
I tried then manually updating build.gradle in ViewServer to use the latest build tools (0.7.+ at the time of posting), but I get the same error with the new gradle version.
Any help and general clarification of how to include non-jar third party libraries would be appreciated!
You probably need to add the repository. Change the gradle.build from:
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 18
buildToolsVersion '18.0.1'
}
to
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 18
buildToolsVersion '18.0.1'
}
I'm only just starting with Android development so I'm sure this is incredibly basic and a dumb question, but I'm getting the following error when I try and include a library to use in my code with Gradle:
Gradle 'MyApp' project refresh failed: You are using an old, unsupported version of Gradle. Please use version 1.6 or greater.
The library I'm trying to use is ION. All I've tried so far is adding the following lines into the build.gradle file.
dependencies {
compile 'com.koushikdutta.ion:ion:1.1.5'
}
Which I guessed at based on this section of Koush's GitHub account, but what else do I need to do? Still download the jar and put it somewhere? I have looked at other questions/searched for guides on the basics of Gradle, but bizarrely I can't find a solid, definitive answer.
And how do I upgrade Gradle? Can it be done from within Android studio? I'm using Android Studio 0.2.13 on Windows 7 64bit:
SOLUTION: - Make sure you're putting the dependencies in the correct build.gradle file! Doh! It should be in the one just above your src folder, not the root!
Make sure that your buildscript contains the classpath with "gradle:0.5.+". Afterwards, navigate to the root directory of your project (one directory level above the build.gradle file) and (in the command line) run "./gradlew clean"
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'MyApp\src\main\AndroidManifest.xml'
}
}
}
dependencies {
compile "com.koushikdutta.ion:ion:1.1.5"
}
I recently switched to android studio for development.
I had created project with minsdk,targetsdk and compile with sdk as Google Api Level 8.
The project compilation fails due to following code in build.gradle file.
dependencies {
compile 'com.android.support:appcompat-v7:18.0.0'
}
Can anyone tell why this is hapenning?
My whole build.gradle is posted below.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 8
buildToolsVersion "18.1.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 8
}
}
dependencies {
compile 'com.android.support:appcompat-v7:18.0.0'
}
Below is the screenshot
You can't compile against any API below 11 and use the AppCompat library. It references the Holo style and the compiler will have no way to resolve those symbols if you're building against an old version.
Get rid of the problem by building against API level 18. This won't break the app for older devices, but you will need to heed the lint API warnings to ensure compatibility. You may have to re-sync the IDE with the gradle files by clicking the gradle icon on the menu bar.
Open "Android SDK Manager"
Install "Extra/Android Support Repository"
I am trying to add a library greenDAO from Github to an Android project created in Android Studio. The content of latest build.gradle created are as follow
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
dependencies {
compile 'com.android.support:appcompat-v7:18.0.0'
}
How to go about doing it?
Any pointer to latest blog on Gradle build system with added help.
GreenDao is on Maven Central (here) so you can reference it in your final dependencies block:
dependencies {
compile 'com.android.support:appcompat-v7:18.0.0'
compile 'de.greenrobot:greendao:1.3.2'
}
Then just reference like you normally would. Android Studio will automatically download the jar file and build it into your app.
Just add compile 'de.greenrobot:greendao-generator:2.1.0' to build.gradle and sync it. You can always check the latest version here.
See this blog post for a step by step greenDAO integration tutorial.
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"