How to make aar in android studio - android

I have the following build.gradle file :
apply plugin: 'android-library'
apply plugin: 'maven'
android {
compileSdkVersion 19
buildToolsVersion '19.1'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
}
}
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
lintOptions {
abortOnError false
}
}
dependencies {
compile project(':olympus-commons')
compile project(':stream-client')
compile project(':door-proxy')
compile 'com.google.guava:guava:17.0'
compile 'to.talk.aragorn:logging:0.1-SNAPSHOT#aar'
compile 'to.talk.aragorn:event-utils:0.1-SNAPSHOT#aar'
compile 'to.talk.aragorn:commons:0.30-SNAPSHOT#aar'
}
def coreAarFile = file('build/conman-client.aar')
artifacts {
archives coreAarFile
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: "http://ci.aws.talk.to:8081/nexus/content/repositories/snapshots",
authentication: [
userName: 'deployer',
password: 'qwedsa'
])
pom.groupId = 'to.talk.legolas'
pom.artifactId = 'conman-client'
pom.version = '1.01-SNAPSHOT'
}
}
}
When i build the module, it builds successfully. But i dont see the conman-client.aar generated. what could be the reason for that?
I read in one of the articles that adding apply plugin: 'android-library' to the build.gradle file will produce the .aar file when the module is built.
But this is not happening. what could be the reason for this ?
Thanks

this is the plugin:
apply plugin: 'com.android.library'
if you add an android library module it will be set automatically and when you build it will create an arr file inside build/outputs/arr

Related

Android Studio 2.1.3 - DefaultSourceDirectorySet issue

Updated Android Studio from 2.1.2 -> 2.1.3 this morning and receiving the following gradle sync error:
Error:Unable to find method
'org.gradle.api.internal.file.DefaultSourceDirectorySet.(Ljava/lang/String;Ljava/lang/String;Lorg/gradle/api/internal/file/FileResolver;)V'.
I'm pretty sure it's related to the following library project:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.7.0'
}
}
apply plugin: 'com.android.library'
apply plugin: 'com.google.protobuf'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
debug {
minifyEnabled false
}
}
sourceSets {
main {
proto {
srcDir 'src/main/protos'
}
java {
srcDir 'src/main/java'
}
manifest {
srcFile 'src/main/AndroidManifest.xml'
}
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:+'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-2'
compile project(':wallpaperpicker-resources')
}
protobuf {
// Configure the protoc executable
protoc {
// Download from repositories
artifact = 'com.google.protobuf:protoc:3.0.0-alpha-3'
}
}
Looks like my previous gradle plugin version was 1.3.0 - am I missing some change that occurred related to the sourceSets block?
Try to update the protobuf version:
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0'
ced's answer led me to the solution. It appears that newer versions of gradle, the Android Studio gradle plugin, and the google protoc plugin wouldn't play nice. I had to upgrade the google protoc plugin as ced noted - but this was a large departure from 0.7.0. The javanano protoc compiler is no longer recommended (and I couldn't get it to work at all). This is the javalite solution that I ended up using.
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0'
}
}
apply plugin: 'com.android.library'
apply plugin: 'com.google.protobuf'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
debug {
minifyEnabled false
}
}
sourceSets {
main {
proto {
srcDir 'src/main/proto'
}
java {
srcDirs = ['src/main/java','$buildDir/generated-sources/release/javalite']
}
manifest {
srcFile 'src/main/AndroidManifest.xml'
}
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.android.support:support-v4:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.google.protobuf.nano:protobuf-javanano:3.0.0-alpha-2'
compile 'com.google.protobuf:protoc-gen-javalite:3.0.0'
compile 'com.google.protobuf:protobuf-lite:3.0.0'
compile project(':wallpaperpicker-resources')
}
protobuf {
generatedFilesBaseDir = "$projectDir/build/generated-sources"
protoc {
// Download from repositories
artifact = 'com.google.protobuf:protoc:3.0.0'
}
plugins {
javalite {
// The codegen for lite comes as a separate artifact
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
}
generateProtoTasks {
all().each { task ->
task.plugins {
javalite {
//remove some of the javalite extra packaging
outputSubDir = ''
}
}
}
}
}
apply plugin: 'idea'
idea {
module {
sourceDirs += file("$buildDir/generated-sources/release/javalite");
}
}

Gradle experimental build.gradle configuration

I'm currently using Android experimental gradle plugin. I need to have multiple custom sub folder in res but when I combine with main java source srcDirs, it will always prompt error message
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException:
Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe''
finished with non-zero exit value 1
my gradle version is 2.5
What is the proper way to configure android.sources for experimental gradle version
in my app's build.gradle file:
apply plugin: 'com.android.model.application'
...
android.sources {
main {
java {
source {
srcDirs = ["src"]
}
}
res{
source {
srcDirs = [ 'src/main/res/property/search',
'src/main/res/property',
'src/main/res/agent',
'src/main/res'
]
}
}
}
}
Current latest and standard configuration which i uses for build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.xyz"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.mikhaellopez:circularimageview:2.0.2'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile files('libs/picasso-2.0.0.jar')
compile 'com.github.rahatarmanahmed:circularprogressview:2.4.0'
}
I think you need to add model tag before android, like it
apply plugin: 'com.android.model.application'
...
model.android.sources {
main {
java {
source {
srcDir = 'src'
}
}
res {
source {
srcDirs = ['src/main/res/property/search',
'src/main/res/property',
'src/main/res/agent',
'src/main/res'
]
}
}
}
}

Error migrating Libgdx project from Eclipse to Android Studio

I'm trying to migrate my existing game (written in libgdx) from Eclipse to Android Studio.
After migrating my desktop project work properly, but I have problem with Android project. In android I'm using Admob ads.
I get the following error message:
As you can see Android Support Repository is installed
My project structure:
In Project Gradle file I have this :
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'org.robovm:robovm-gradle-plugin:1.9.0'
}
}
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
version = '1.0'
ext {
appName = 'My Game'
gdxVersion = '1.7.1'
roboVMVersion = '1.9.0'
box2DLightsVersion = '1.4'
ashleyVersion = '1.7.0'
aiVersion = '1.6.0'
}
repositories {
jcenter()
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url 'https://oss.sonatype.org/content/repositories/releases/' }
}
}
project(":desktop") {
apply plugin: "java"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
}
}
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
compile project(":core")
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.4.0'
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
compile fileTree(dir: '../libs', include: '*.jar')
}
}
project(":ios") {
apply plugin: "java"
apply plugin: "robovm"
configurations { natives }
dependencies {
compile project(":core")
compile "org.robovm:robovm-rt:$roboVMVersion"
compile "org.robovm:robovm-cocoatouch:$roboVMVersion"
compile "com.badlogicgames.gdx:gdx-backend-robovm:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-ios"
}
}
project(":html") {
apply plugin: "gwt"
apply plugin: "war"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
compile "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion:sources"
compile "com.badlogicgames.gdx:gdx-box2d-gwt:$gdxVersion:sources"
}
}
project(":core") {
apply plugin: "java"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
compile fileTree(dir: '../libs', include: '*.jar')
}
}
tasks.eclipse.doLast {
delete ".project"
}
Here is Android Gradle file:
apply plugin: 'com.android.application'
android {
buildToolsVersion "23.0.2"
compileSdkVersion 23
defaultConfig {
targetSdkVersion 23
}
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')
}
}
// needed to add JNI shared libraries to APK when compiling on CLI
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniFolders = new HashSet<File>()
pkgTask.jniFolders.add(new File(projectDir, 'libs'))
}
// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives() {
file("libs/armeabi/").mkdirs();
file("libs/armeabi-v7a/").mkdirs();
file("libs/x86/").mkdirs();
configurations.natives.files.each { jar ->
def outputDir = null
if (jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
if (jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
if (jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
if (outputDir != null) {
copy {
from zipTree(jar)
into outputDir
include "*.so"
}
}
}
}
task run(type: Exec) {
def adb = "$System.env.ANDROID_HOME/platform-tools/adb"
commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.flexsolutions.bubbles.era.android/com.flexsolutions.bubbles.era.android.AndroidLauncher'
}
// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
// need to specify Java source sets explicitely, SpringSource Gradle Eclipse plugin
// ignores any nodes added in classpath.file.withXml
sourceSets {
main {
java.srcDirs "src", 'gen'
}
}
jdt {
sourceCompatibility = 1.6
targetCompatibility = 1.6
}
classpath {
plusConfigurations += project.configurations.compile
containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'
}
project {
name = appName + "-android"
natures 'com.android.ide.eclipse.adt.AndroidNature'
buildCommands.clear();
buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
buildCommand "org.eclipse.jdt.core.javabuilder"
buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
}
}
// sets up the Android Idea project, using the old Ant based build.
idea {
module {
sourceDirs += file("src");
scopes = [COMPILE: [plus: [project.configurations.compile]]]
iml {
withXml {
def node = it.asNode()
def builder = NodeBuilder.newInstance();
builder.current = node;
builder.component(name: "FacetManager") {
facet(type: "android", name: "Android") {
configuration {
option(name: "UPDATE_PROPERTY_FILES", value: "true")
}
}
}
}
}
}
}
I have tried to change android support to other version , but I get same error.
Any help would be appreciated.
Thanks
I think that your problem with importing the project is caused by this
buildToolsVersion "19.1.0"
compileSdkVersion 19
You're trying to use an older buildTools than your Android Support libraries:
compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.0'
All you need to do is change the values above to 21.
Just follow these steps:
Prerequirements
Make sure that you've downloaded the latest extras as well as the
Android 5.0 SDK via the SDK-Manager.
Android Studio
Open the build.gradle file of your app-module and change your
compileSdkVersion to 21. It's basically not necessary to change the
targetSdkVersion SDK-Version to 21 but it's recommended since you
should always target the latest android Build-Version. In the
end you gradle-file will look like this:
android {
compileSdkVersion 21
// ...
defaultConfig {
// ...
targetSdkVersion 21
}
}
Be sure to sync your project afterwards.
Change also your buildToolsVersion:
buildToolsVersion "19.1.0"
to
buildToolsVersion "21.1.2"
It should work
If you would like to make your project more recent than above, here's an build.gradle of my Android project created a while ago:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.piotr.myapplication"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services:8.4.0'
}
EDIT: Something still missing. Try these steps
Update your dependencies to the latest version as above.
Add this line
`apply plugin: 'com.android.application' before
before
`android {
buildToolsVersion "19.1.0"`
and change
repositories {
mavenCentral()
...
with
repositories {
jcenter()
mavenCentral()
...
Hope it help
Finally I find solution
I created blank new libGDX project using libGDX project setup with same package as my previous setup, and I copy all of my classes from old project to this new one. After all done I get working version of my code.
I didn't notice any differences in buld.gradle filed as comments and #piotrek1543 answers.
I don't know what was problem exactly, but my project now work.
I hope this will help anyone in future!
Very Sad, This error comes up every time I include nexus repository manager in the gradle setup
repositories{
maven{ url "http://localhost:8081/nexus/content/groups/public/" }
}
I was forced to remove delete the local nexus repository, and it compiles. I feel more and more, google is insensitive to the needs of developers from developing countries where internet is really expensive and slow.
i was forced to leave just
repositories{
jcenter()
}

Parse.com - can't find build.gradle file

ParseStarterProject is really, really frustrating. I tried to add Google Play services to compile in build.gradle and it don't wanted to sync. Then I removed it to make it work again, but it showed that there is settings.gradle file missing. When I tried to create it by myself - it fails to save it... Now I have Failed to resolve: com.parse.bolts:bolts-android:1.2.0 and I don't know what to do with it. I want to make a new project from scratch and copy my code, but seems like it's more complicated than just copy & paste.
ParseStarterProject.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.parse'
buildscript {
repositories {
mavenCentral()
jcenter()
maven { url 'https://maven.parse.com/repo' }
}
dependencies {
classpath 'com.parse.tools:gradle:1.+'
}
}
dependencies {
compile 'com.parse.bolts:bolts-android:1.2.0'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
compile fileTree(dir: 'libs', include: 'ParseCrashReporting-*.jar')
}
android {
compileSdkVersion 22
buildToolsVersion "20"
defaultConfig {
minSdkVersion 9
targetSdkVersion 22
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
/* Uncomment if you enable ProGuard and you want to automatically upload symbols on build.
parse {
applicationId YOUR_APPLICATION_ID
masterKey YOUR_MASTER_KEY
// Make symbol upload automatic. Otherwise, use e.g. ../gradlew parseUploadSymbolsDebug;
uploadSymbols true
}
*/
build.gradle
// 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:1.1.3'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
ext {
compileSdkVersion = 22
buildToolsVersion = "22"
minSdkVersion = 9
targetSdkVersion = 22
}

ActionBarSherlock (library) on Android Studio

I had the problem like wired00 on Problems importing project into Android Studio regarding ActionBarSherlock
I do exactly the solution (Edit2) but when I run I get
Gradle: package com.actionbarsherlock.app does not exist
Strange thing is that on code I don't get any error, just on compiling.
Update 1:
build.gradle:
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 7
targetSdkVersion 16
}
}
MainActivity:
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockActivity;
public class MainActivity extends SherlockActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Module Settings:
Structure:
Error:
I think you need to add the following dependency in you gradle file:
compile project(':StoKit:actionbarsherlock')
(within the dependency section)
EDIT 25/05/2013
Ok, so this is my project structure which is currently compiling fine in android studio and via gradle command line:
EDIT 31/05/2013
Ok, so my build.gradle file within DecisionBuddy-DecisionBuddy module is:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
repositories{
mavenCentral()
}
dependencies {
compile project(':libraries:actionbarsherlock')
compile files('libs/GoogleAdMobAdsSdk-6.3.1.jar')
compile files('libs/libGoogleAnalyticsV2.jar')
compile files('libs/mobileservices-0.2.0.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
}
And the one in the actionbarsherlock module is:
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android-library'
dependencies {
compile files('../../DecisionBuddy/libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
Does this help?
Also make sure you updated to the latest version of the tools - I was having some issues until I did that.
I had the same problem and solve it by adding
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
to the dependencies of the build.gradle of the slidingMunu library project.
here is my build.gradle
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:18.0.+'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
}
android {
compileSdkVersion 16
buildToolsVersion '20.0.0'
defaultConfig {
minSdkVersion 16
targetSdkVersion 21
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}

Categories

Resources