I'm using Android Studio 0.3.7 (latest) and Gradle 1.8. I'm currently getting the following error when I rebuild a simple test project that has a dependency on an equally simple test library project stored in a Sonotype Nexus local repository.
:UtilsUserApp:compileDefaultFlavorDebug/Users/ymedialabs/AndroidStudioProjects/UtilsUser/UtilsUserApp/src/main/java/com/ymedia/utilsuserapp/MainActivity.java:13: error: package com.ymedia.android.utils does not exist import com.ymedia.android.utils.UIUtils; ^ /Users/ymedialabs/AndroidStudioProjects/UtilsUser/UtilsUserApp/src/main/java/com/ymedia/utilsuserapp/MainActivity.java:27: error: package com.ymedia.android.utils does not exist String hello = com.ymedia.android.utils.UIUtils.getHello(); ^ 2 errors FAILED
Before reaching this stage, I was getting a different error that indicated that Gradle wasn't finding my dependency. The current message seems to indicate that I'm missing something that puts the library dependency on the project classpath.
Here's build.gradle for the APK project
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
maven {
url = 'http://localhost:8081/nexus/content/groups/public'
}
}
android {
compileSdkVersion 19
buildToolsVersion '19.0.0'
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
productFlavors {
defaultFlavor {
proguardFile 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.ymedia:utils:1.0.0'
}
I'm using Sonatype Nexus in its out of the box configuration with this ~/.m2/settings.xml
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
What bit of configuration is missing or in error?
Here is the output of running ./gradlew from the commandline:
macbook-pro:UtilsUser labs$ ./gradlew clean assemble --refresh-dependencies Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0 :UtilsUserApp:clean :UtilsUserApp:preBuild UP-TO-DATE :UtilsUserApp:preDefaultFlavorDebugBuild UP-TO-DATE :UtilsUserApp:preDefaultFlavorReleaseBuild UP-TO-DATE :UtilsUserApp:prepareComAndroidSupportAppcompatV71900Library :UtilsUserApp:prepareDefaultFlavorDebugDependencies :UtilsUserApp:compileDefaultFlavorDebugAidl :UtilsUserApp:compileDefaultFlavorDebugRenderscript :UtilsUserApp:generateDefaultFlavorDebugBuildConfig :UtilsUserApp:mergeDefaultFlavorDebugAssets :UtilsUserApp:mergeDefaultFlavorDebugResources :UtilsUserApp:processDefaultFlavorDebugManifest :UtilsUserApp:processDefaultFlavorDebugResources :UtilsUserApp:generateDefaultFlavorDebugSources :UtilsUserApp:compileDefaultFlavorDebug /Users/ymedialabs/AndroidStudioProjects/UtilsUser/UtilsUserApp/src/main/java/com/ymedia/utilsuserapp/MainActivity.java:13: error: package com.ymedia.android.utils does not exist import com.ymedia.android.utils.UIUtils; ^ /Users/ymedialabs/AndroidStudioProjects/UtilsUser/UtilsUserApp/src/main/java/com/ymedia/utilsuserapp/MainActivity.java:27: error: package com.ymedia.android.utils does not exist String hello = com.ymedia.android.utils.UIUtils.getHello(); ^ 2 errors :UtilsUserApp:compileDefaultFlavorDebug FAILED
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ':UtilsUserApp:compileDefaultFlavorDebug'.
The build.gradle for the library project is below.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
repositories {
maven {
url "http://localhost:8081/nexus/content/groups/public/"
}
}
apply plugin: 'maven'
apply plugin: 'signing'
version = "1.0.0-SNAPSHOT"
group = "com.ymedia.android"
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)
}
snapshotRepository(url: sonatypeSnapshotRepo ) {
authentication(userName: sonatypeUsername,
password: sonatypePassword)
}
pom.project {
name 'YMedia UI Utilities'
packaging 'aar'
description 'UI utilities'
/*
url 'file://localhost/Users/ymedialabs/AndroidStudioProjects/Utils/utils/build/libs/utils-debug.aar'
scm {
url 'scm:[email protected]:VandalSoftware/android-cache-lib.git'
connection 'scm:[email protected]:VandalSoftware/android-cache-lib.git'
developerConnection 'scm:[email protected]:VandalSoftware/android-cache-lib.git'
}
*/
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
developers {
developer {
id 'mark.rosenberg'
name 'Mark Rosenberg'
email '[email protected]'
}
}
}
}
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
}
release {
runProguard false
proguardFile 'proguard-rules.txt'
proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
}
}
dependencies {
}
I've added the recommended target to show the APK project's classpath. The artifact being loaded has a .asc extension which would explain why the jar is not being seen during the build.
ys-macbook-pro:UtilsUser ymedialabs$ ./gradlew showClasspath Relying on packaging to define the extension of the main artifact has been deprecated and is scheduled to be removed in Gradle 2.0 :UtilsUserApp:showClasspath /Applications/Android Studio.app/sdk/extras/android/m2repository/com/android/support/appcompat-v7/19.0.0/appcompat-v7-19.0.0.aar /Users/ymedialabs/.gradle/caches/artifacts-26/filestore/com.ymedia/utils/1.0.0/aar.asc/8a55d3ff3a51dff343226e85c8e64b1f912e2ff3/utils-1.0.0.aar.asc /Applications/Android Studio.app/sdk/extras/android/m2repository/com/android/support/support-v4/19.0.0/support-v4-19.0.0.jar
BUILD SUCCESSFUL