My objective is to compile a library that depends on other libraries (from HoloEverywhere), which are present in a remote maven repository, using Gradle and Android Studio (0.4.4).
If I set apply plugin: to android in the library's build.gradle, the remote maven dependencies are found, otherwise they are not (apply plugin: 'android-library').
Here is my build.gradle with the android object omitted to save in space:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
maven {url 'http://192.241.191.41/repo'}
}
android {...}
dependencies {
compile 'org.holoeverywhere:library:2.1.0#aar'
compile 'org.holoeverywhere:addon-preferences:2.1.0#aar'
compile fileTree(dir: 'libs', include: '*.jar')
}
The error I get when I press "Sync Project with Gradle Files" in Android Studio is:
7:30:48 PM Failed to refresh Gradle project 'MyTopProject'
Could not find org.holoeverywhere:library:2.1.0.
Required by:
MyTopProject:MyActualApp:unspecified > MyTopProject:MyMessedUpLib:unspecified
Search in build.gradle files
What am I doing wrong? Is this behaviour expected? Should I do it in another way?
Thank you very much.
Related
I'm trying to use Push Notifications with Firebase Cloud Messaging and Cordova FCM. My google-services.json located in root folder with config.xml and same file in platforms/android/ folder. With ionic cordova build I got error:
A problem occurred configuring root project 'android'.
Cannot add task ':processDebugGoogleServices' as a task with that name already exists.
I've installs:
cordova plugin add cordova-support-google-services --save
ionic cordova plugin add cordova-plugin-fcm
npm install --save #ionic-native/fcm
and previously by another reason:
cordova plugin add cordova-plugin-googleplus ...
Now what I got:
platforms/android/cordova-plugin-fcm/myapp-FCMPlugin.gradle:
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:+'
classpath 'com.google.gms:google-services:3.0.0'
}
}
// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
platforms/android/cordova-support-google-services/myapp-build.gradle:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:+'
classpath 'com.google.gms:google-services:3.2.0'
}
}
// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
ext.postBuildExtras = {
apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
}
platforms/android/project.properties:
target=android-26
android.library.reference.1=CordovaLib
cordova.system.library.1=com.google.android.gms:play-services-auth:11.0.1
cordova.system.library.2=com.google.android.gms:play-services-identity:11.0.1
cordova.system.library.3=com.facebook.android:facebook-android-sdk:4.14.+
cordova.system.library.4=com.google.firebase:firebase-core:+
cordova.system.library.5=com.google.firebase:firebase-messaging:11.0.1
cordova.gradle.include.1=cordova-plugin-fcm/myapp-FCMPlugin.gradle
cordova.gradle.include.2=cordova-support-google-services/myapp-build.gradle
which is edited from:
target=android-26
android.library.reference.1=CordovaLib
cordova.system.library.1=com.google.android.gms:play-services-auth:+
cordova.system.library.2=com.google.android.gms:play-services-identity:+
cordova.system.library.3=com.facebook.android:facebook-android-sdk:4.14.+
cordova.system.library.4=com.google.firebase:firebase-core:+
cordova.system.library.5=com.google.firebase:firebase-messaging:+
cordova.gradle.include.1=cordova-plugin-fcm/myapp-FCMPlugin.gradle
platforms/android/build.gradle which is also edited as project.properties:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// SUB-PROJECT DEPENDENCIES START
debugCompile(project(path: "CordovaLib", configuration: "debug"))
releaseCompile(project(path: "CordovaLib", configuration: "release"))
compile "com.google.android.gms:play-services-auth:11.0.1"
compile "com.google.android.gms:play-services-identity:11.0.1"
compile "com.facebook.android:facebook-android-sdk:4.14.+"
compile "com.google.firebase:firebase-core:+"
compile "com.google.firebase:firebase-messaging:11.0.1"
// SUB-PROJECT DEPENDENCIES END
}
plugins/cordova-plugin-fcm/scr/android/FCMPlugin.gradle:
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:+'
classpath 'com.google.gms:google-services:3.0.0'
}
}
// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
plugins/cordova-support-google-services/build.gradle:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:+'
classpath 'com.google.gms:google-services:3.2.0'
}
}
// apply plugin: 'com.google.gms.google-services'
// class must be used instead of id(string) to be able to apply plugin from non-root gradle file
ext.postBuildExtras = {
apply plugin: com.google.gms.googleservices.GoogleServicesPlugin
}
Not sure what is wrong, advice would be helpful
The problem is you have conflicting versions of the GoogleServices plugin specified in your Gradle config:
/plugins/cordova-plugin-fcm/scr/android/FCMPlugin.gradle
com.google.gms:google-services:3.0.0
plugins/cordova-support-google-services/build.gradle
com.google.gms:google-services:3.2.0
You need to resolve this so the versions match.
I have a project that need to use protobuf (Getting the objects from server and parsing them).
For that I configured the following things:
Project level gradle.build
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.7.0'
classpath 'com.google.protobuf:protobuf-java:2.6.1'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App level gradle.build
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.protobuf'
android {
...
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:2.6.1'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.google.protobuf:protobuf-java:2.6.1'
compile 'com.google.protobuf:protobuf-gradle-plugin:0.7.0'
}
I put my proto file under .../app/src/main/proto/FILE.proto.
Once i am trying to build the project I am getting the following error:
Error:Execution failed for task ':app:generateDebugProto'.
> protoc: stdout: . stderr: /Users/XX/YY/app/build/extracted-protos/main: warning: directory does not exist.
/Users/XX/YY/app/build/extracted-include-protos/main: warning: directory does not exist.
...
protoc-gen-javanano: program not found or is not executable
--javanano_out: protoc-gen-javanano: Plugin failed with status code 1.
Any idea why is that? It should use the protoc from the repo and is should support that nano compilation.
Thanks.
Finally i downloaded the source from GitHub and compiled it. It fixed the issue because it includes the missing binary.
compile('com.twitter.sdk.android:tweet-composer:0.8.0#aar')
{
transitive = true;
}
i got gradle from https://dev.twitter.com/twitter-kit/android/compose
But when Sync the Android Studio project following error is coming ..
Error:(53, 13) **Failed to resolve: **com.twitter.sdk.android:tweet-composer:0.8.0****
Show in FileShow in Project Structure dialog
As was described on twitter, you have to change some parts in your module build.gradle.
In your module you can use:
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// The Fabric Gradle plugin uses an open ended version to
// react quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
//Put Fabric plugin after Android plugin
apply plugin: 'io.fabric'
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
I suggest you installing the Android Studio plugin.
It helps you to configure the gradle script.
This help me
https://dev.twitter.com/twitterkit/android/installation
dependencies {
// Include all the Twitter APIs
compile 'com.twitter.sdk.android:twitter:3.0.0'
// (Optional) Monetize using mopub
compile 'com.twitter.sdk.android:twitter-mopub:3.0.0'
}
OR
enter code dependencies {
compile 'com.twitter.sdk.android:twitter-core:3.0.0'
compile 'com.twitter.sdk.android:tweet-ui:3.0.0'
compile 'com.twitter.sdk.android:tweet-composer:3.0.0'
compile 'com.twitter.sdk.android:twitter-mopub:3.0.0'
}
I've tried to included cards library in my project using the below code in my build.gradle file.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
dependencies {
//Core card library
compile 'com.github.gabrielemariotti.cards:cardslib-core:2.0.1'
//Optional for built-in cards
compile 'com.github.gabrielemariotti.cards:cardslib-cards:2.0.1'
//Optional for RecyclerView
compile 'com.github.gabrielemariotti.cards:cardslib-recyclerview:2.0.1'
//Optional for staggered grid view support
compile 'com.github.gabrielemariotti.cards:cardslib-extra-staggeredgrid:2.0.1'
//Optional for drag and drop support
compile 'com.github.gabrielemariotti.cards:cardslib-extra-dragdrop:2.0.1'
//Optional for twowayview support (coming soon)
//compile 'com.github.gabrielemariotti.cards:cardslib-extra-twoway:2.0.1'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
But when compiling, android studio is throwing up errors as below.
Error:(23, 0) Gradle DSL method not found: 'compile()'
Possible causes:The project 'cardslib_1' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
Apply Gradle plugin
I'm guessing the reason to be gradle version, which is lower in libraries I'm including.
How to know the gradle version my dependencies are using and how to adjust them to my project.
When I thought to add the libraries, maven has repositories in aar file which I don't think will let you know the gradle version.
Thanks for any help in this regards.
You're adding the dependencies in the wrong place. They should be outside of the buildscript section and in the modules/applications build.gradle.
Parent build.gradle. This should be in the root directory of your project
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
Module build.gradle. This should be in the folder of the module you're trying to add the dependencies to.
apply plugin: 'com.android.application'
android {
// Android related settings go here
}
dependencies {
compile 'com.github.gabrielemariotti.cards:cardslib-core:2.0.1'
compile 'com.github.gabrielemariotti.cards:cardslib-cards:2.0.1'
compile 'com.github.gabrielemariotti.cards:cardslib-recyclerview:2.0.1'
compile 'com.github.gabrielemariotti.cards:cardslib-extra-staggeredgrid:2.0.1'
compile 'com.github.gabrielemariotti.cards:cardslib-extra-dragdrop:2.0.1'
}
This assumes that the structure of your project is something like
Project
|___build.gradle
|___Module
|____build.gradle
I have a build.gradle file in my library project, the content of it looks like below:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:18.0.+'
.......
when I do gradle build, it gives error:
Could not find com.actionbarsherlock:actionbarsherlock:4.4.0.
If I change the line "apply plugin" from 'android-library' to 'android', it can compile fine.
So is it a bug with the gradle android plugin? that it cannot find actionbarsherlock correctly in maven repository if it's from a library project?
Make sure you select from Project Settings -> Gradle, "Use local gradle distribution" pointing to you local Gradle copy. Mine is 1.9 and I managed to make it work.