How to use buildship for android? - 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.

Related

Include generated Jar and aar as a dependency in Android project

I have a AndroidStudioSupport Project which has modules.
1. module 1 takes care of Android UI part
2. module 2 is a library project which generates .aar file
3. module 3 is a java project which generates jar file
Now I want to build the project in a way that
1. First build jar project
2. Then copy generated jar into libs of library project as a dependency
3. Then build aar file
4. Then copy generated aar into libs of UI project as a dependency
5. Finally generate .apk file
Please suggest me what changes do I have to do in my gradle files
jar project gradle file
apply plugin: 'java'
sourceSets {
main.java.srcDirs = ['src/main/java']
main.resources.srcDirs = ['src/main/java']
test.java.srcDirs = ['tests/java']
test.resources.srcDirs = ['tests/resources']
}
jar {
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it)}
}
}
library project gradle file
apply plugin: 'com.android.library'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':java_project')
}
task copyToLib(type: Copy) {
from configurations.compile
into 'libs'
}
build.dependsOn(copyToLib)
android {
publishNonDefault true
compileSdkVersion 21
buildToolsVersion '23.0.2'
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src/main/java']
aidl.srcDirs = ['src/main/java']
renderscript.srcDirs = ['src/main/java']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('test')
}
buildTypes {
debug {
jniDebuggable true
}
}
}
This current implementation doesn't include jar from my java project

Plugin with id 'com.android.library' not found [duplicate]

This question already has answers here:
Android Studio: Plugin with id 'android-library' not found
(10 answers)
Closed 6 years ago.
I am receiving this error, when I try to use a library project in Android Studio. The specific line in build.gradle that gives this error is
apply plugin: 'com.android.library'
I even tried changing it to
apply plugin: 'android-library'
Bu it still doesn't work, instead it says: Error:(7, 0) Plugin with id 'android-library' not found.
I even tried to add:
classpath 'com.android.tools.build:gradle:1.2.3.+'
under dependencies in build.gradle, and still nothing...
Any help?
EDIT: The whole build.gradle
// This buildscript will assemble the MoPub SDK into an AAR.
repositories {
jcenter()
}
apply plugin: 'android-library'
group = 'com.mopub'
description = '''MoPub SDK'''
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
versionCode 25
versionName "3.8.0"
minSdkVersion 9
targetSdkVersion 22
consumerProguardFiles 'proguard.txt'
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src/main/java']
aidl.srcDirs = ['src/main']
renderscript.srcDirs = ['src/main']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), file('proguard.txt')
}
}
// Note: You will also need a local.properties file to set the location of the SDK in the same
// way that the existing SDK requires, using the sdk.dir property.
// Alternatively, you can set an environment variable called ANDROID_HOME. There is no
// difference between the two methods, you can use the one you prefer.
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3.+'
compile 'com.android.support:support-v4:22.0.0'
compile 'com.android.support:support-annotations:22.0.0'
compile 'com.mopub.volley:mopub-volley:1.1.0'
}
// Don't run the Robolectric Unit Tests.
check.dependsOn.remove("test")
check.dependsOn.remove("unitTest")
check.dependsOn.remove("testDebug")
check.dependsOn.remove("unitTestDebug")
You need to write this:
apply plugin: 'com.android.application'
Replace this code in your file too:
buildscript {
repositories {
mavenCentral() // or jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3' // 1.3.0-beta2
}
}

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.

play_licensing throws AIDL error with downloader_library for APK Expansion with Gradle

I tried to use the APK Expansion libs zip_file and downloader_library (which requires play_licensing). zip_file worked fine since it has no dependencies, but play_licensing throws an error when I try a Gradle sync.
Android Studio spits out this error log:
Information:Gradle tasks [:app:generateGoogleDebugSources, :app:libs:downloader_library:generateDebugSources, :app:libs:play_licensing:generateDebugSources, :app:libs:zip_file:generateDebugSources]
Information:/Users/faiz/Projects/Android/TogetherTime/app/libs/play_licensing/aidl/ILicenseResultListener.aidl:21 interface ILicenseResultListener should be declared in a file called com/android/vending/licensing/ILicenseResultListener.aidl.
Information:2 errors
Information:0 warnings
Information:See complete output in console
/Users/faiz/Projects/Android/TogetherTime/app/libs/play_licensing/aidl/ILicensingService.aidl
Error:(19) couldn't find import for class com.android.vending.licensing.ILicenseResultListener
Error:(19) Execution failed for task ':app:libs:play_licensing:compileReleaseAidl'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Users/faiz/Projects/Android/android-sdk-macosx/build-tools/19.0.3/aidl -p/Users/faiz/Projects/Android/android-sdk-macosx/platforms/android-19/framework.aidl -o/Users/faiz/Projects/Android/TogetherTime/app/libs/play_licensing/build/source/aidl/release -I/Users/faiz/Projects/Android/TogetherTime/app/libs/play_licensing/aidl -I/Users/faiz/Projects/Android/TogetherTime/app/libs/play_licensing/src/release/aidl -d/var/folders/y6/g0d5m3f94rxdvq5myp53d9k80000gn/T/aidl662748145109587430.d /Users/faiz/Projects/Android/TogetherTime/app/libs/play_licensing/aidl/ILicensingService.aidl
Error Code:
1
Output:
/Users/faiz/Projects/Android/TogetherTime/app/libs/play_licensing/aidl/ILicensingService.aidl:19: couldn't find import for class com.android.vending.licensing.ILicenseResultListener
I haven't modified any of the libraries, but since they weren't built for Gradle, I copied over a build.gradle from another project and modified them accordingly.
downloader_library/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:+'
compile project(':app:libs:play_licensing')
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
defaultConfig {
minSdkVersion 4
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
play_licensing/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:+'
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
aidl.srcDirs = ['aidl']
}
}
defaultConfig {
minSdkVersion 3
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
I'm currently using Android Studio 0.5.1 and gradle 0.9.0 with build tools 19.0.3
I had the same problem and found solution for it. Just create a new package with the name com.android.vending.licensing under the aidl folder and move your aidl files there:
P.S. you also have to add empty <application /> tags to AndroidManifest.xml of play_licensing and downloader_library modules. And compile project(':PlayLicensing') to the dependencies tag of the build.gradle of the downloader_library

Google Maps in Android Studio

I am trying to get Google Maps into my application from within Android Studio. I found a tutorial which suggested openning up my .grade file:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
and add this line to dependencies:
compile 'com.google.android.gms:play-services:3.2.25'
I added this line and my .grade file looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
compile 'com.google.android.gms:play-services:3.2.25'
}
}
apply plugin: 'android'
dependencies {
}
android {
compileSdkVersion 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')
}
}
When I added this line, and tried to rebuild my project I get this error:
Gradle: A problem occurred evaluating root project 'BeerPortfolioPro'.
> No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.compile() is applicable for argument types: (java.lang.String) values: [com.google.android.gms:play-services:3.2.25]
Possible solutions: module(java.lang.Object)
Update:
I tried changing my .grade from one of the answers below to this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
}
android {
compileSdkVersion 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')
}
}
and now I get this error:
Gradle: A problem occurred configuring root project 'BeerPortfolioPro'.
> Failed to notify project evaluation listener.
> Could not resolve all dependencies for configuration ':_DebugCompile'.
> Could not find com.google.android.gms:play-services:4.0.30.
Required by:
:BeerPortfolioPro:unspecified
Open your SDK Manager and install/update the Android Support Repository, Android Support Library v19, Google Repository and Google Play Service v13.
I had a similar "No signature of method" error, and realised that I'd added the dependency to the wrong file. When creating my project, Android Studio created 2 build.gradle files, one in the project root directory (alongside local.properties and gradle.properties), and one in a subdirectory named after my app (alongside the src and build directories). The play-services dependency needs to be added to the latter of these files, not the former.
The dependencies block in your buildscript section is for including files required for the gradle build script. Google Play Services should be in the "app" `dependencies' section.
Here's a suggestion buildscript solution.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
}
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')
}
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile 'com.google.android.gms:play-services:4.0.30'
}
Extra Notes
classpath 'com.android.tools.build:gradle:0.6.+'
This will make sure you have the latest gradle 6 build tools.
Also the following block will make sure you're using the latest SDK version and build tools, while still including SDK 11 as the minimum supported version. Build Tools v19.0.0 has improvements over previous versions, but also plays nicely with Java 7.
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
}
If you cannot reference play-service 4 then a temporary solution could be to reference play-services:3.2.25 as specified in the documentation. A better solution would be to upload the library to your own maven repository (like Sonatype Nexus) and pull the dependency from there.
It's the minSdkVersion problem. Change it to 14, for Android 4.0.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:4.0.30'
compile 'com.android.support:appcompat-v7:+'
}

Categories

Resources