0

I'm a newbie in Android especially for libs.

I'm using Android Studio 1.2.2

I'm trying to create a jar library with no activity, resources, etc (only code) that use the AltBeacon library. When complete I whould like to include this jar in my APP that has to use beacons through my lib.

Well, using AltBeacon instructions, I'm able configure gradle to have a "normal" (with activity etc) APP using AltBeacon library. But I'm not able to create a jar library that contains the AltBeacon one. I google a lot especially in SO, I found a lot of questions about "library inside library" but that doesn't worked for me.

I made this:

  • I created an empty project with Studio (blank activity)
  • Then I created a new module -> Java Library and called it libmebeaconmanager and Studio created a new Java class that I called MeBeaconManager
  • I modified the build.gradle of the library in this way:

    apply plugin: 'java'

    dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'org.altbeacon:android-beacon-library:2+'

    }

This is the build.gradle of Module:app:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0 rc2"

    defaultConfig {
        applicationId "me.padovame.libbeacontest"
        minSdkVersion 18
        targetSdkVersion 22
        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:22.2.0'
}

And this is the build.gradle of project:

// 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'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}
  • At this point, in the MeBeaconManager class of the lib, I tried to import AltBeacon classes without success because I got an undefined symbol error for import lines like this:

    import org.altbeacon.beacon.Beacon;

I also tried, without success, inserting in lib folder of libmebeaconmanager the downloaded android-beacon-library-2.3.aar

What am I doing wrong?

Thanks in advance.

EDIT: I tried to include a jar (tried with Picasso) library in my libmebeaconmanager and it worked. So the problem seems to be with aar libs.

I'm going crazy...

EDIT 2: I extracted classes.jar from the AltBeacon aar lib and used as other jar and it worked.

But I consider this as a workaround: I still do not understand how to manage directly aar files. So thanks to whom can help me.

maxbeltra
  • 21
  • 4

1 Answers1

0

Seems like there is a problem in inserting library to project structure

You can have a look at answer provided by user Sam Rad here:
How do I add a library project to Android Studio?

Community
  • 1
  • 1
Adi Tiwari
  • 761
  • 1
  • 5
  • 17
  • Unfortunately import module option is not more available in Android Studio... and that post is for adding a lib to a project, not for adding a lib to a lib – maxbeltra Jun 30 '15 at 13:29
  • I don't know which version of android studio you are taking about @maxbeltra. But i am using Android studio 1.0.1 and this support is there, actually in my knowledge this support has been enabled after studio 0.53 – Adi Tiwari Jun 30 '15 at 13:35
  • I'm using Android Studio 1.2.2 – maxbeltra Jun 30 '15 at 14:06
  • The import module now wants a directory, not an aar file. I tried also New module -> add existing aar/JAR. I gave the path to albeacon aar lib and it modified the build.gradle of the lib in this way: dependencies { compile fileTree(include: ['*.aar'], dir: 'libs') // compile 'org.altbeacon:android-beacon-library:2+@aar' compile project(':android-beacon-library-2.3') } but I got the same error – maxbeltra Jun 30 '15 at 14:12