Android Gradle library dependency with library dependency using Nexus - android

I'm switching my project over to using Gradle and an internal SonaType Nexus for hosting my dependencies. My core project depends on library project A and library project A has a dependency on library project B.
My issue is that as soon as I add LibA to my main project I get this error:
"Module version com.example:LibA:1.1 depends on libraries but is not a library itself"
I have no issues adding library projects with jar dependencies with the same build script. I have seen people doing this successfully with LOCAL (in the project) android libraries but no one doing it with maven repos.
Is this a bug in gradle or did I misconfigure the library builds?
Core Project Build
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
maven {
url "http://localhost:8081/nexus/content/repositories/releases/"
}
maven {
url "http://localhost:8081/nexus/content/repositories/central/"
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
}
dependencies {
compile 'com.android.support:support-v4:+'
compile('com.example:LibA:1.+')
}
LibA Build
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 17
versionCode = "3"
versionName = "1.2"
}
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aild.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile ('com.example:LibB:1.+')
} ...
LibB Build
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 9
targetSdkVersion 17
versionCode = "1"
versionName = "1.0"
}
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aild.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
repositories {
mavenCentral()
}
dependencies {
} ...
Edit: Adding -info output for the error.
* What went wrong:
A problem occurred configuring project ':GradleTest'.
> Failed to notify project evaluation listener.
> Module version com.example:LibA:1.+ depends on libraries but is not a library itself
Edit 2: Adding my local maven upload script for LibA
apply plugin: 'maven'
apply plugin: 'signing'
group = "com.example"
version = defaultConfig.versionName
configurations {
archives {
extendsFrom configurations.default
}
}
signing {
required { has("release") && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}
uploadArchives {
configuration = configurations.archives
repositories.mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: sonatypeRepo) {
authentication(userName: sonatypeUsername,
password: sonatypePassword)
}
pom.project {
name 'com-example'
packaging 'aar'
description 'none'
url 'https://internal github link'
scm {
url 'scm:git#https://internal github link'
connection 'git#https://internal github link'
developerConnection 'git#https://internal github link'
}
licenses {
license {
name 'example'
url 'example'
distribution 'example'
}
}
developers {
developer {
id 'example'
name 'example'
email 'example'
}
}
groupId "com.example"
artifactId rootProject.name //LibA
version defaultConfig.versionName
}
}
}

Your line in the dependencies to include LibA is wrong. To include a library project, use this:
compile project(':LibA')
If the library's directory isn't at the root of your project directory, you'll need to specify a colon-delimited path. For example, if your directory structure is:
projectFolder
|
+--coreProject
|
+--libraries
|
+--LibA
|
+--LibB
your dependency will be:
compile project(':libraries:LibA')
This is the same as the notation you use in your settings.gradle file.

Maybe problem is that you use mavenCentral as your repository for library projects
repositories {
mavenCentral()
}
and not yours nexus repository where actual dependencies exists
repositories {
maven {
url "http://localhost:8081/nexus/content/repositories/releases/"
}
maven {
url "http://localhost:8081/nexus/content/repositories/central/"
}
}

If you uploaded library artifact for both jar and aar, try this.
compile 'com.example:LibA:1.1.1#aar'

In my work, I have used compile project(':google-play-services_lib') instead of compile ('google-play-services_lib') when I declare dependent projects in my build.gradle file. I think that is the right way to do this with Gradle: http://www.gradle.org/docs/current/userguide/dependency_management.html#sub:project_dependencies

if you don't want to have it as sub-module in the first build.gradle file you can add your local maven repository
mavenLocal()
//repositories
repositories {
mavenCentral()
mavenLocal()
}
but you need to run install on libA first.

I had a similar error message after introducing by mistake a cyclic dependency between libraries:
build.gradle in commons-utils
dependencies {
...
instrumentTestCompile project(':test-utils')
}
build.gradle in test-utils
dependencies {
...
compile project(':commons-utils')
}
Fixing this solved the problem. The error message is not very explicit.

Don't know for sure, just a couple of thoughts:
Have you tried running gradle assemble instead gradle build? This should skip tests, as I see error is related to test task.
Maybe stupid, but try to remove dependcy on 2nd lib from the first and put it to your main build file listing before the first. I have a memory of something related. This way the second lib may be added to classpath allowing the first to compile.
Try to create .aar files by hand and upload it to repo also by hand.
It's a hack, but maybe it'll work: have you considered to exclude this :GradleTest module? See section 50.4.7

This issue has gone away with the later versions of Gradle and the Android Gradle Plugin. Seems to have just been an early release bug.

Related

Qt Android output apk generated in ~/android-build\build\outputs\apk\debug

Problem: I want to use Android build system (gradle version 3) with Qt project, but this version of gradle (compared to old version 2) would change location of generated output apk file to be under $buildDir/outputs/apk/debug instead of $buildDir/outputs/apk (added debug folder), but when Qt Android kit tries to install app to Android device it only looks in old location, and fails to locate the apk file. I checked with Android Studio and its same which indicates gradle 3 is working normal
old location: $build_folder/android-build\build\outputs\apk\my.apk
New location: $build_folder/android-build\build\outputs\apk\debug\my.apk
Error (Compile):
adb: error: cannot stat
'D:/Qt/FireBase/build-client01-Android_for_armeabi_v7a_GCC_4_9_Qt_5_11_0_for_Android_armv73-Release/android-build//build/outputs/apk/android-build-debug.apk':
No such file or directory
This problem occurs only when I make changes to default build.gradle generated by Qt to set gradle to version 3, the default generated file have classpath set to old version 2.3.3,
old: classpath 'com.android.tools.build:gradle:2.3.3'
new : classpath 'com.android.tools.build:gradle:3.1.0
There are other changes I made, that also require change in gradle-wrapper.properties, here are updated files:
build.gradle
buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
//classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:4.0.1' // google-services plugin
classpath 'com.android.tools.build:gradle:3.1.0'
}
}
allprojects {
repositories {
jcenter()
//google() // Google's Maven repository
maven {
url "https://maven.google.com"
}
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
android {
/*******************************************************
* The following variables:
* - androidBuildToolsVersion,
* - androidCompileSdkVersion
* - qt5AndroidDir - holds the path to qt android files
* needed to build any Qt application
* on Android.
*
* are defined in gradle.properties file. This file is
* updated by QtCreator and androiddeployqt tools.
* Changing them manually might break the compilation!
*******************************************************/
compileSdkVersion androidCompileSdkVersion.toInteger()
buildToolsVersion androidBuildToolsVersion
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = [qt5AndroidDir + '/src', 'src', 'java']
aidl.srcDirs = [qt5AndroidDir + '/src', 'src', 'aidl']
res.srcDirs = [qt5AndroidDir + '/res', 'res']
resources.srcDirs = ['src']
renderscript.srcDirs = ['src']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}
lintOptions {
abortOnError false
}
}
dependencies {
// ...
//libfirebase_auth.a
//libfirebase_app.a
implementation 'com.google.firebase:firebase-core:16.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.2'
implementation 'com.google.android.gms:play-services-base:15.0.1'
// Getting a "Could not find" error? Make sure you have
// added the Google maven respository to your root build.gradle
}
apply plugin: 'com.google.gms.google-services'
gradle-wrapper.properties
#Mon Feb 20 10:43:22 EST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
I use this on my build.gradle :
android {
...
applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "../" + outputFileName
}
}
}
I still don't know where and how to instruct Qt to look into new output structure, but as a workaround for now , I added configuration to build.gradle to make a copy of the generated apk back to ~/apk where Qt looks for!
// make a copy of APK from "$buildDir/outputs/apk/debug" back to "$buildDir/outputs/apk"
def archiveBuildTypes = ["release", "debug"];
applicationVariants.all { variant ->
variant.outputs.all { output ->
if (variant.buildType.name in archiveBuildTypes) {
def taskSuffix = variant.name.capitalize()
def assembleTaskName = "assemble${taskSuffix}"
if (tasks.findByName(assembleTaskName)) {
def copyAPKFolderTask = tasks.create(name: "archive${taskSuffix}", type: org.gradle.api.tasks.Copy) {
description "copy APK to old folder"
def sourceFolder = "$buildDir/outputs/apk/$output.baseName"
def destinationFolder = "$buildDir/outputs/apk"
print "Copy apk from: $sourceFolder into $destinationFolder\n"
from(sourceFolder)
into destinationFolder
eachFile { file ->
file.path = file.name // so we have a "flat" copy
}
includeEmptyDirs = false
}
tasks[assembleTaskName].finalizedBy = [copyAPKFolderTask]
}
}
}
}
Update:
gradle 3.1.x and higher require at least androidBuildToolsVersion 27, while Qt currently supports no higher than androidBuildToolsVersion 26, So practically may be its safer to fall back to gradle 3.0.x which supports build tools 26
It's also even possible to fall back to gradle 2.3.3 (use compile instead of implementation for FireBase and any required modules:
compile 'com.google.firebase:firebase-core:16.0.1'
...

How to resolve the Android Studio error where it cannot find the project's Manifest file?

I am migrating my legacy project from Eclipse to Android studio. I did the following things:
Export and generate gradle build files in eclipse
Imported the Gradle.build file in Android Studio
Changed my gradle version dependencies to: classpath 'com.android.tools.build:gradle:0.9.+'
My root folder of the project contains 3 library projects: Actionbarsherlock, Authbahn and library. My root folder also contains the main project called JohelpenHulpverlener.
After resolving a lot of errors I get the following error:
Error:A problem was found with the configuration of task ':checkDebugManifest'.
> File 'C:\android\jeugdformaat\JohelpenHulpverlener\AndroidManifest.xml' specified for property 'manifest' does not exist.
My root build.gradle looks like this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
compile project(":actionbarsherlock")
}
android {
compileSdkVersion 17
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
My build.gradle in the main project looks like this:
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':library')
compile project(':actionbarsherlock')
compile project(':autobahn')
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
I am trying to understand this, hopefully someone can help me out here!
You've got a bunch of stuff in your root-level Gradle build file that's making the build system think there's an Android module there (it's not; it's a subdirectory below inside JohelpenHulpverlener) , and it's failing because it's not finding the manifest.
I think if you take a lot of stuff out of your root-level build.gradle file and replace it with the default version for new projects, which is this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
it will work.
Make sure you have tags on the outside like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0" >
...
</manifest>
In build.gradle file specify package name like
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.myapp"
minSdkVersion 11
targetSdkVersion 19
versionCode 27
versionName "1.5.6"
}
}
applicationId "com.myapp" Here "com.myapp" is packagename of my app.
I hope this will help you.
I had the same problem when migrating eclipse project to android studio.
The problem is that the root Gradle build file created by android studio is wrong and it should be like this :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
allprojects {
repositories {
jcenter()
}
}
Update : It seems the problem has been fixed by Android Studio's latest version 1.4, now we can easily import eclipse project into studio
Build->Rebuild solved it for me.
I know this is an old post, but I helped a friend who is new to programming with this problem last night. Your suggestions were examined but did not apply. Their last action before the error was to add a list view layout to the project. I asked them to delete it and the errors vanished after a few moments.
I have not found any other post with this scenario and this conclusion so I thought sharing it here might help someone else.
Conclusion: Adding a new component to the wrong place may be another reason for such an error.

Android Studio 0.4.0 + ABSherlock + gradle without "import module"

In the 3rd answer here:
How do I add a library project to Android Studio?
I found informations about how we can add ABSherlock library to project using gradle in Android Studio. But in this way we use "import module" option which doesn't exist any more in Android Studio 0.4.0. So how should I add ABSherlock or other library now ? (using gradle)
You can add this part to your build.gradle script
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
}
EDIT:
If you are using also the support library you can use it:
dependencies {
compile 'com.android.support:support-v4:19.0.0'
compile ('com.actionbarsherlock:actionbarsherlock:4.4.0#aar'){
// Need to specifically exclude this as it is specified in ActionBarSherlock pom
exclude group: 'com.google.android', module: 'support-v4'
}
}
EDIT2:
If you would like to work with abs with a local copy ( I suggest you to use the maven dependency ) you can do this:
-root
-lib
-abs
build.gradle
src
res
-myModule
build.gradle
settings.gradle
In settings.gradle:
include ':myModule', ':lib:abs'
In lib/abs/build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion XX
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.0.0'
}
Remove the supportV4.jar from your local abs library.
In myModule/build.gradle you should add:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion XX
targetSdkVersion 19
}
}
dependencies {
// Libraries
compile project(':lib:abs')
}
If in myModule/build.gradle you need to use the support library, you should add:
dependencies {
compile 'com.android.support:support-v4:19.0.0'
// Libraries
compile project(':lib:abs')
}
Working with gradle you should prefer to use dependencies in Maven.
However you can use local libraries with this structure above, editing your gradle files.

Android Gradle library dependency

Hi I have following android project:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
}
repositories {
mavenCentral()
}
android {
buildToolsVersion "17.0"
compileSdkVersion 17
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
Now I would like to add another dependency: https://github.com/bauerca/drag-sort-listview.
I tried adding
compile 'com.mobeta.android.dslv:drag-sort-listview:0.6.1-SNAPSHOT'
but it doesn't work. How can I add this project as a Gradle dependency?
I saw that there is an option to copy this library as a subdirectory in my project dir. How should I include such a project?
The author of the library has to upload #aar bundle to maven central repository to make it work. As you can see drag sort listview is no longer mainted by author. You can use repo from the community as temporal solution.
repositories {
mavenCentral()
maven {
url 'https://github.com/Goddchen/mvn-repo/raw/master/'
}
}
dependencies {
compile files('libs/android-support-v4.jar')
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.mobeta.android.dslv:drag-sort-listview:0.6.1'
}
In general case you have to download sources and add them as library to your project.
I like to recommend you to use this library instead.
I thinks https://github.com/ened is thanksfully made the library for gradle and maintained it for a while.
compile 'asia.ivity.android:drag-sort-listview:1.0'
<dependency>
<groupId>asia.ivity.android</groupId>
<artifactId>drag-sort-listview</artifactId>
<version>1.0</version>
</dependency>
http://mvnrepository.com/artifact/asia.ivity.android/drag-sort-listview/1.0
https://github.com/ened/drag-sort-listview

Gradle error with Android project added as a library (SlidingMenu) [package does not exist]

I've never used Gradle before so I'm completely lost!
I've added SlidingMenu as a library and I have access from my project to all the SlindingMenu stuff, but trying to compile will give me this error:
Gradle: package com.jeremyfeinstein.slidingmenu.lib does not exist
I'm using Android Studio (so IntelliJ) and this is my gradle.build
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 17
}
}
Thanks in advance
Assuming you have added SlidingMenu.jar into libs folder, right click on it -> Add as library. Then change in gradle.build:
Before:
dependencies {
compile files('libs/android-support-v4.jar')
}
After:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
This will include all your jar files.
I had the same problem. Adding sliding-menu-lib from with gradle-build as android library did help me.
My project structure is as:
-MyDemoProject
-build.gradle
-settings.gradle
--MyDemo
--build.gradle
--libs
---sliding-menu-lib
----res
----src
----AndroidManifest.xml
----build.gradle
--src
To make all the stuff working your settings.bundle should have this contents:
include ':MyDemo' ':MyDemo:libs:sliding-menu-lib'
There is a trick here, which allows you avoid errors while building project with gradle using Android Studio, as according to Android Tools Manual you should use ':libs:sliding-menu-lib' but that does not work due to issue with relative projectDir paths.
Your MyDemo/build.gradle should contain dependencies like:
dependencies {
compile 'com.android.support:support-v4:18.0.0'
...
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':MyDemo:libs:sliding-menu-lib')
}
And your sliding-menu-lib/build.gradle should be like:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 14
buildToolsVersion "18.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 14
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
Most important part deals with sourceSets section as you may not want change sliding-menu-lib file structure (non-default for current gradle)
I added all of my previous libraries using the default import from source tool. For SlidingMenu I used the import with Maven then deleted all of the Maven dependancies from the Project Settings for SlidingMenu and reimported the Support libraries. This seemed to clear most issues up for me.
If the module is just a library and not a stand-alone app, it's gradle should contain
apply plugin: 'android-library'
instead of
apply plugin: 'android'
You can Sync Project with Gradle Files:
Tools -> Android -> Sync Project with Gradle Files
Recently found better solution for SlidingMenu separately:
You can add SlidingMenu as generated #aar file if you do not need to make any changes to it. Just use https://github.com/jzaccone/SlidingMenu-aar and make changes as in Readme file there.
Be careful with order of repos. This one should be above mavenCentral()

Categories

Resources