Add Ant Library Project into my Gradle project - android

I have a Gradle Android project, which includes an Ant library project: https://github.com/pakerfeldt/android-viewflow.
How can I include this Ant library project in my build.gradle file? I tried to added "ant.importBuild 'lib/viewflow/build.xml'" but didn't work.
Is there anything missing or mistake here?
Thanks

This is a similar question to android-studio-library-not-recognizing-the-android-api.
In the viewflow directory you'll need to create a build.gradle file with the following content:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10.+'
}
}
apply plugin: 'android-library'
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
compileSdkVersion 19
buildToolsVersion "19.0.3"
lintOptions {
abortOnError false
}
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
}
You have the option of including the generated AAR file into your project's libs folder like the linked question or you can copy the viewflow project into your projects root directory and include it as a module by modifying your settings.gradle and adding it your project's dependency section using compile project:
compile project(':viewflow')

Related

How to use buildship for android?

I have a dummy project, which I succeed to compile through buildship plugin in eclipse IDE.
This is my local.properties file:
sdk.dir=C:/Asta/altro/adt-bundle/sdk
This is settings.gradle file
rootProject.name = 'testgradle'
This is my build.gradle file
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.testgradle"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
lintOptions {
abortOnError false
}
}
sourceCompatibility = 1.6
targetCompatibility = 1.6
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
dependencies {
compile 'org.slf4j:slf4j-api:1.7.21'
compile 'com.android.support:appcompat-v7:23.4.0'
testCompile 'junit:junit:4.12'
}
task wrapper(type: Wrapper) {
gradleVersion = '2.10'
}
Despite I got the apk fully compiled, eclipse is not integrated: still seeing missing libraries and giving more than a 100 errors! All the libs are perfectly managed by gradle in \build\intermediates\ and assembled into apk, but the eclipse IDE is not "live". I would like to use gradle to download and explode the libraries and then to inform eclipse and let it to make the apk with its own builder.
Buildship can be used only to run Android tasks (assembleDebug).
During the build process it will load dependencies and tell if there're some errors.
To load dependencies into Java classpath, to see errors in Eclipse and resolve imports you can either manually add .jar files to your Java Build Path or use this Gradle plugin: https://github.com/greensopinion/gradle-android-eclipse.
It generates classpath for Eclipse project and you just import it into the IDE.
To run Gradle tasks you can create a Run configuration (named "Gradle Project") and put there your task and Working directory.

Problems with SlidingMenu integration

I have been trying to use the SlidingMenu library in my Android Studio project following the guide provided in this question:
How to import slidingmenu on Android Studio?
I've been able to obtain the described file structure and sync&build the project without errors. Yet, when trying to import the Sliding Menu to my apps source files, I'm getting a symbol resolve error.
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu; // Error message: Cannot resolve symbol 'SlidingMenu'
import com.jeremyfeinstein.slidingmenu.lib.BuildConfig;
The second import is the only one suggested by Android Studio but I can't even find the BuildConfig file in my project when following the given path.
What do I need to change to be able to import all the classes in com.jeremyfeinstein.slidingmenu.lib to my own classes?
My apps gradle files looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.me.appname"
minSdkVersion 17
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.0.0'
compile 'com.google.android.gms:play-services:7.0.0'
compile project(':libraries:SlidingMenu')
}
The SlidingMenu gradle file:
buildscript {
// define the repo which is to use
repositories {
mavenCentral()
}
// define the classpath for Gradle Android Plugin
dependencies {
classpath 'com.android.tools.build:gradle:1.0.+'
}
}
// declaring that the project is a library
apply plugin: 'android-library'
// declaring all dependencies the project needs
dependencies {
compile 'com.android.support:support-v4:19.0.0'
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
// this values you can read out from the Manifest (but I add the right values for you)
minSdkVersion 17
targetSdkVersion 21
}
// because Android Studio has a different file structure than Eclipse
// you have to say Android Studio where the files are located
sourceSets{
main{
java.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
manifest.srcFile 'AndroidManifest.xml'
}
}
}
Project settings gradle:
include ":libraries:SlidingMenu", ':app'
Get the AAR port of the library (v1.3).
The GitHub Pages is down, so you'll have to import that AAR manually:
Top build.gradle file:
repositories {
flatDir {
dirs 'libs'
}
}
Place the AAR file in the libs folder of your module, then in your module build.gradle file:
dependencies {
compile(name:'library-1.3', ext:'aar')
}

How to use the gradle to build appcompat(support v7) by myself?

I'm having a problem building APKs in IntelliJ using gradle.Because I import the appcompat library and use the android-library to build it by myself.There are no build errors and output the apk successful.But when you install the apk to phone which has Android 2.3,the action bar is fullscreen.But api >= 14 is totally normal.like this
wrong link:
right link:
But if I use the appcompat library by importing dependency,the apk is normorl.So my problem is why I can’t build appcompat by hand?
Here is my project structure
picture link:
the root project’s build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
}
}
apply plugin: 'com.android.application'
dependencies {
// compile "com.android.support:appcompat-v7:19.1.0"
compile project(":appcompat")
}
ext {
compileSdkVersion = 21
buildToolsVersion = "21.1.2"
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion 8
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
appcompat project’s build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
}
}
apply plugin: 'com.android.library'
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/android-support-v7-appcompat.jar')
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
res.srcDirs = ['res']
java.srcDirs = ['src']
}
}
}
settings.build:
include ':appcompat'
Besides,I use gradle 2.2.1,support-v7 19.1.0.
The whole project can download here:
project
Anyone who know this?
Just add to dependencies:
compile 'com.android.support:appcompat-v7:21.0.3'
You shouldn't include jar's of the libraries that are available via repositories.
Note: Don't forget to update the support libraries in SDK Manager.

Different gradle versions for library and application

I'm currently trying to add a library relying on froger_mcs' answer in this post.
Unfortunately, I didn't manage to find build.gradle in library's source files to complete last step:
At the end you have to create another build.gradle file in /libriaries/actionbarsherlock/ directory.
So I added one found in gipi's answer here.
I ended up facing the following problem:
When I run ./gradlew clean it says that gradle version 1.9 is required for the library I'm trying to add. When I change version in gradle-wrapper.properties to 1.9 and run the same task again, it says that gradle version 1.8 is required for my application.
What am I missing?
MyProject/external/TheLibrary/build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
MyProject/MyApp/build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
}
}
dependencies {
compile project(':external:TheLibrary')
/* other dependencies */
}
MyProject/settings.gradle:
include ':external:TheLibrary', ':MyApp'
Try adding latest version of gradle that is avaliable.
Put in your build.gradle located on root (MyProject in ur case)
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
Plus you don't need to specify gradle for each project. You can put it in your main build.gradle and other libs will read from it. Mine build.gradle looks like that in listing below. And for your case build.gradle will be in root directory MyProject. So you want to edit global build.gradle not the ones that are inside modules (MyApp and TheLibrary). You can delate your claspath to gradles in those modules - make only one globaly.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Put in your gradle wrapper:
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip
And I think that build tools might be a main problem here. Make every of your lib projects to have the same build tool variant as your main project so, swtich from:
compileSdkVersion 17
buildToolsVersion "17.0.0"
to:
compileSdkVersion 19
buildToolsVersion "19.0.0"
And btw. there is 19.0.3 avaliable.

Android Studio gradle and libraries import

I have successfully imported ActionBarSherlock to my project, and need to import another two libraries: Sliding Layer and Crouton. I know that similar questions have already appeared here before, but I've tried almost everything, each time breaking something in the project in a way that I had to start over.
My project tree looks like:
MyProject/
+ app/
+ libraries/
+ actionbarsherlock/
+ crouton/
+ slidinglayer/
I imported those two libraries as modules (File->Import Module)
My setting.gradle file looks like it should:
include ":libraries:actionbarsherlock", ':Krypto', ':libraries:crouton', ':libraries:slidinglayer'
actionbarsherlock gradle:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
app gradle:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile project(":libraries:actionbarsherlock")
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
slidinglayer gradle:
apply plugin: 'android-library'
dependencies {
compile "com.android.support:support-v4:18.0.0"
}
android {
compileSdkVersion 18
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 4
targetSdkVersion 18
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
In crouton folder there is no gradle.build file. How it should look like? Theres only java files (no resources).
How to set up correctly dependencies in crouton and slidinglayer libraries?
build.gradle for crouton
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
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 9
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
}
}
}
and in your app build.gradle, change
dependencies {
compile project(":libraries:actionbarsherlock")
}
to
dependencies {
compile project(":libraries:actionbarsherlock")
compile project(":libraries:crouton")
compile project(":libraries:slidinglayer")
}
and import again in Android Studio
I don't know how to solve your problem, but when I faced problem of third party library use in Gradle build, I solved by following way.
Following is my structure of project.
GsonDemoProject
GsonDemo
build
libs
android-support-v4.jar
gson.jar
src
main
build.gradle
build.gradle
settings.gradle
I edited my build.gradle file which resides in src directory.
dependencies {
compile files('libs/android-support-v4.jar','libs/gson.jar')
}
I put reference of 3rd party library in dependencies tag like above. In my project libs is directory where libraries are put.

Categories

Resources