0

I want to create a library of my own project which include java source code, resources (manifest, layout) file and I'm using Android Studio 2.1.2. Please give me any suggestions how I can create that one and also following one - 1) Want to create .jar library not .AAR.
2) How to add another library or any dependencies in to it, is it possible??

Thanks in advance.

Milad Yarmohammadi
  • 1,253
  • 2
  • 22
  • 37

3 Answers3

0

You just need to change in your app's build.gradle file

search line

apply plugin: 'com.android.application'

and change it to

apply plugin: 'com.android.library'

and most important thing remove line

applicationId "your_package_name"

from the defaultConfig block. because libraries do not have application Id. and then build your project you'll find 'aar' folder inside you build folder.

projectfolder -> build -> output -> aar -> library_file

Edited :

and for Jar file please go through with the below command

Run gradlew makeJar command from your project root.

Community
  • 1
  • 1
SilentKiller
  • 6,944
  • 6
  • 40
  • 75
0

see these tutorials... How to make a .jar out from an Android Studio project

http://www.technetexperts.com/mobile/export-jar-file-from-android-studio-project/

Community
  • 1
  • 1
Milad Yarmohammadi
  • 1,253
  • 2
  • 22
  • 37
  • 1) **http://stackoverflow.com/questions/21712714/how-to-make-a-jar-out-from-an-android-studio-project** will create only source code how can i add my resources?? – Rajan Nalawade Sep 29 '16 at 06:18
  • 2) **http://www.technetexperts.com/mobile/export-jar-file-from-android-studio-project/** will create jar but after adding this .jar file in to another project it gives error of missing configuration files – Rajan Nalawade Sep 29 '16 at 06:20
  • error - **android.content.ActivityNotFoundException: Unable to find explicit activity class {'pakage name of another app'.tabexample/'pakage name of library'.NextActivity}; have you declared this activity in your AndroidManifest.xml?** – Rajan Nalawade Sep 29 '16 at 06:36
0

build.gradle file

build.gradle file  apply plugin: 'com.android.library'
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'

        classpath 'com.google.gms:google-services:3.0.0'
    }
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    publishNonDefault true

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets {
         main {
             //Path to your source code
            java {
                srcDir 'src/main/java'
            }
            resources {
                srcDir 'src/../lib'
            }
        }
    }

    // This is important, it will run lint checks but won't abort build
    lintOptions {
        abortOnError false
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile files('libs/AdvancedWebView.jar')
    compile project(':ShortcutBadger')
    compile files('libs/commons-net-3.4.jar')
    compile files('libs/ksoap2-android-assembly-3.6.0-jar-with-dependencies.jar')
}

task clearJar(type: Delete) {
    delete 'release/' + POM_ARTIFACT_ID + '_' + VERSION_NAME + '.jar'
}

task makeJar(type: Copy) {
    from('build/intermediates/bundles/debug/')
    into('release/')
    include('classes.jar')
    rename ('classes.jar', POM_ARTIFACT_ID + '_' +  VERSION_NAME + '.jar')
}

makeJar.dependsOn(clearJar, build)

and this is my mainifest file

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="package name">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-feature android:name="android.hardware.camera" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
        android:allowBackup="true"
        android:label="@string/app_name"
        android:supportsRtl="true">

        <activity android:name=".SplashScreen"
            android:label="@string/app_name"/>

        <activity
            android:name=".MainActivity"                
     android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:label="@string/app_name" >
        </activity>

        <activity android:name=".NextActivity"
            android:label="@string/app_name"/>

    </application>

</manifest>