How i can export Android code to java library in Android Studio

user6289326

I'm developing a library for an Android application, I wrote some classes that contains different functions.

I have a problem in the exporting process from Java to Jar. I did the following:

1) From an existing source code, File -> New module -> Java Library

2) Android Studio at this point create a "sub project", with a default class

3) Cut and paste my java code in the library created at point 2

At this point I have some problems/questions:

  • Some part of code cannot be resolved like ByteBuffer, JSON...

  • Should I import in the JSON - HTTP library?

  • I don't understand why ConnectivityManager, NetworkInfo cannot be resolved.

EDIT 1

Step 1 - App Project

New module -> Java Library

app gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

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

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile files('libs/httpcore-4.4.4.jar')
}

Di gradle

apply plugin: 'java'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

Project gradle

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

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

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Aurasphere

The problem is that you are moving the code in another subproject and then building it differently. To fix this, assuming you are using Android Studio, move into your module Gradle.build file all the library you need in the new module.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How i can export Android code to java library in Android Studio

From Dev

How can I link native library in Android Studio?

From Dev

in Android Studio, how can I change an app project to a library?

From Dev

How can I link native library in Android Studio?

From Dev

How can I use this Github library in android studio

From Dev

How can I build an .aar library with shrunk classes in Android Studio?

From Dev

How do I export an Android Studio project?

From Dev

How can I intercept a method call to a library class in Java or Android?

From Dev

How can i run Jacoco in android studio for code coverage

From Dev

I can't figure out how to add Downloader Library and Licensing Library to Android Studio

From Dev

How can I import a new module (android library project) using Android studio 0.3.0

From Dev

How can I import a new module (android library project) using Android studio 0.3.0

From Dev

How can I validate day month and year in Java Android Studio,

From Dev

How can I validate day month and year in Java Android Studio,

From Dev

How can I access to the resources of a library for Android?

From Dev

How can i create a Radio group in java code in Android?

From Dev

Why can't I use the support library in Android Studio?

From Dev

I can't debug a library in Android-Studio

From Dev

how can i show android:icon in android menu ( android studio)

From Dev

Can't import a standard java library class in Android Studio

From Dev

Can't import a standard java library class in Android Studio

From Dev

How can I find an Android encryption library or class compatible with my C# code?

From Dev

Where can I see the code generated by Android Data Binding Library?

From Dev

Can I integrate android code in java applications?

From Dev

How do I get dagger 2 to work with Android studio java library project

From Dev

How do I get dagger 2 to work with Android studio java library project

From Dev

How can I reset the Android studio layout?

From Dev

How can I install Android Studio?

From Dev

how can I update the path to Android Studio?

Related Related

  1. 1

    How i can export Android code to java library in Android Studio

  2. 2

    How can I link native library in Android Studio?

  3. 3

    in Android Studio, how can I change an app project to a library?

  4. 4

    How can I link native library in Android Studio?

  5. 5

    How can I use this Github library in android studio

  6. 6

    How can I build an .aar library with shrunk classes in Android Studio?

  7. 7

    How do I export an Android Studio project?

  8. 8

    How can I intercept a method call to a library class in Java or Android?

  9. 9

    How can i run Jacoco in android studio for code coverage

  10. 10

    I can't figure out how to add Downloader Library and Licensing Library to Android Studio

  11. 11

    How can I import a new module (android library project) using Android studio 0.3.0

  12. 12

    How can I import a new module (android library project) using Android studio 0.3.0

  13. 13

    How can I validate day month and year in Java Android Studio,

  14. 14

    How can I validate day month and year in Java Android Studio,

  15. 15

    How can I access to the resources of a library for Android?

  16. 16

    How can i create a Radio group in java code in Android?

  17. 17

    Why can't I use the support library in Android Studio?

  18. 18

    I can't debug a library in Android-Studio

  19. 19

    how can i show android:icon in android menu ( android studio)

  20. 20

    Can't import a standard java library class in Android Studio

  21. 21

    Can't import a standard java library class in Android Studio

  22. 22

    How can I find an Android encryption library or class compatible with my C# code?

  23. 23

    Where can I see the code generated by Android Data Binding Library?

  24. 24

    Can I integrate android code in java applications?

  25. 25

    How do I get dagger 2 to work with Android studio java library project

  26. 26

    How do I get dagger 2 to work with Android studio java library project

  27. 27

    How can I reset the Android studio layout?

  28. 28

    How can I install Android Studio?

  29. 29

    how can I update the path to Android Studio?

HotTag

Archive