i am working on an android using GCM application and adding support libraries,i added the following to my gradle
i added a plugin
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
and dependencies: i added:
compile 'com.google.android.gms:play-services:8.3.0'
classpath 'com.google.gms:google-services:3.0.0'
but it brings an error
Error:(3, 0) Plugin with id 'com.google.gms.google-services' not found.
and yet i see the plugin added. how to i correct it thank you
In your project level build.gradle add like following:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
While your App level build.gradle should look like this:
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.google.android.gms:play-services-gcm:8.3.0"
}
apply plugin: 'com.google.gms.google-services'
Make sure to add apply plugin: 'com.google.gms.google-services' as last line in your app level gradle file.
You should only apply the com.android.application plugin.
Applying the java plugin as well will result in a build error.
Reference : http://tools.android.com/tech-docs/new-build-system/user-guide
The dependencies you have added are fine. You can remove the "apply plugin: 'com.google.gms.google-services'" entry.
Related
I've gotten the kie-maven-plugin to work with maven, but when using it with gradle I get the error plugin with id 'kie-maven-plugin' not found. I've added the kie-maven-plugin coordinates to both the plugin repository section as well as the project dependencies section with no luck (as well as either/or). Am I getting the apply plugin line right?
In buildscript -> repositories -> dependencies section:
classpath 'org.kie:kie-maven-plugin:7.35.0.Final'
In allprojects section:
apply plugin: 'kie-maven-plugin'
In allprojects -> dependencies section:
compile group: 'org.kie', name: 'kie-maven-plugin', version: "7.35.0.Final"
I've also tried the following to no avail:
apply plugin: 'org.kie.maven.plugin'
apply plugin: 'kie'
apply plugin: 'org.kie'
apply plugin: 'org.kie.kie'
apply plugin: 'org.kie.kie-maven-plugin'
apply plugin: 'org.kie:kie-maven-plugin'
apply plugin: 'org.kie.maven.plugin.ValidateDMNMojo'
After a lot of searching, it was the last option to raise it here! In eclipse, I am designing such project structure using Gradle, as shown below...
Algorithms //Parent Project
-SubModuleCore //Child Project for common utilities & dependencies
-build.gradle
-SubModuleOne //Child project for any operation
-build.gradle //Added 'SubModuleCore' as a dependency like compile project(':SubModuleCore')
-SubModuleTwo //Child project for another operation
-build.gradle //Added 'SubModuleCore' as a dependency like compile project(':SubModuleCore')
-build.gradle
-settings.gradle
Services //Stand-Alone project
-build.gradle //Here I want to add 'Algorithms' as a single dependency
-settings.gradle
Project structures are same in eclipse work-space as shown above. I am able to generate individual .jar of Algorithms project. So the problem is I want to add this Algorithms project as a single dependency in project Services like compile project(':Algorithms'). But eclipse just saying 'shut-up!'. I don't want to publish it somewhere like maven central / jitpack etc. instead I want to do it locally. I'm trying this way...
Services/build.gradle
apply plugin: 'war'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
project.webAppDirName = 'WebContent'
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile fileTree(dir: 'lib', include: ['*.jar'])
compile project(':Algorithms')
}
Services/settings.gradle
rootProject.name = 'Services'
include 'Algorithms'
project(':Algorithms').projectDir = new File(settingsDir, '../Algorithms')
Algorithms/build.gradle
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = "1.8";
targetCompatibility = "1.8";
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = "1.8";
targetCompatibility = "1.8";
buildscript {
dependencies {
repositories {
jcenter()
mavenCentral()
}
}
}
repositories {
jcenter()
mavenCentral()
}
}
subprojects.each { subproject ->
evaluationDependsOn(subproject.path)
}
jar.dependsOn subprojects.tasks['classes']
jar {
baseName = 'algorithms'
subprojects.each { subproject ->
from subproject.sourceSets.main.output.classesDir
}
from files('resources/log4j2.xml')
from files('resources/application.properties')
}
Algorithms/settings.gradle
rootProject.name = 'Algorithms'
include ':SubModuleCore', ':SubModuleOne', ':SubModuleTwo'
I tried several solutions from SO, still not succeeded. Somebody please help me, I got stuck badly here. It seems I am very close to this, but don't know what is missing!
Thanks
You can use the includeBuild feature.
Declare the included build in Services/settings.gradle
rootProject.name='Services'
includeBuild '../Algorithms'
and then express the dependency using
compile "${project.group}:${project.name}"
where project group and name the one from the Algorithms project.
Here is my project build.gradle:
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:3.1.0'
}
}
In one of the module's build.gradle I have this:
apply plugin: 'com.google.gms.google-services'
which results into the following error:
Could not get unknown property 'LibraryVariants' for object of type com.android.build.gradle.LibraryExtension.
Fun fact, if I set google-services version to 3.0.0, this specific error disappears, but Gradle asks me to downgrade versions of other google libraries, but I really do not want to do that.
How do I deal with these LibraryVariants?
You only set apply plugin: 'com.google.gms.google-services' in the app module, and in no other modules.
You must add one dependencies in your build.gradle(Project:project_name)
classpath 'com.google.gms:google-services:3.1.0'
And add in your build.gradle(build.gradle:Module app)
apply plugin: 'com.google.gms.google-services'
dependencies {
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
}
apply plugin: 'com.google.gms.google-services'
I am trying to use DexGuard plugin in Java project whith Gradle. It is library project for android.
But i want to link DexGuard library whitout:
apply plugin: 'com.android.application'
Because I need to use:
apply plugin: 'java'
Is it possible to use DexGuard plugin such a way?
I need this way to use because i need to use an additional plugin:
apply plugin: 'com.github.johnrengelman.shadow'
And I have a problem to use this plugin in conjunction whith android plugin...
My gradle:
buildscript {
repositories {
jcenter()
flatDir dirs: 'DexGuard/lib'
}
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.2'
classpath ':dexguard'
}
}
apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '**/*.jar')
}
sourceSets {
main {
java.srcDirs = ['src']
}
}
shadowJar {
...
}
task sdkDexguard(type: com.saikoa.dexguard.gradle.DexGuardTask) {
configuration 'dexguard.txt'
injars 'build/classes'
injars 'libs'
outjars 'build/application.apk'
}
I can not to build tasklist. Error in line task sdkDexguard:
Could not find property 'com' on root project
UPD
Problem in the library DexGuard 6.1.11 for standalone usage. GuardSquare team will solve that soon.
Problem solved in version 7.0.31. Now possible to use this method for standalone usage.
I tried to import a project(projLib) as dependency for another project(projAPK).
projAPK gradle has this :
dependencies {
compile project(':libs:NewsAPI')
compile project(':projLib')
}
but when i sync the gradle it gives this error:
Error:Dependency Android_2015:projLib:unspecified on project projAPK resolves to an APK archive which is not supported as a compilation dependency. File: /Users/myname/Documents/Development/Android_2015/libs/projAPK/build/outputs/apk/projLib-release-unsigned.apk
so I guess there are two solution to this:
somehow make gradle think that projLib is a library that shouldn't be compiled to apk
somehow make gradle NOT compile the projLib explicitly
The problem is, I couldn't find how to do any of that.
Would be awesome if you guys can help :)
In projLib's build.gradle file, you'll see a statement like this:
apply plugin: 'com.android.application'
which tells Gradle to build it as an application, generating an APK. If you change it to this:
apply plugin: 'com.android.library'
it will build as a library, generating an AAR, and it should work.
If you also need projLib to generate a separate APK, then you'll have to do some refactoring to pull the common code that you need out into a third library module, and have both APKs depend on it.
Libraries aren't allowed to set an applicationId, so if you see an error message to that effect, remove it from the library's build script.
In module gradle file-
Replace apply plugin: 'com.android.application' with apply plugin: 'com.android.library'
Then remove applicationId "xxx.xxx.xxxx"
Clean and Build
just add these lines to library gradle file and remove other sections
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:gridlayout-v7:23.1.1'
,...
}
For Kotlin DSL (build.gradle.kts), use this notation:
plugins {
id("com.android.library")
// ...
}