繁体   English   中英

我如何将Android代码导出到Android Studio中的Java库

[英]How i can export Android code to java library in Android Studio

我正在为Android应用程序开发库,我编写了一些包含不同功能的类。

从Java到Jar的导出过程中出现问题。 我做了以下工作:

1)从现有的源代码中,选择File-> New module-> Java Library

2)此时,Android Studio创建一个带有默认类的“子项目”

3)在第2点创建的库中剪切并粘贴我的Java代码

在这一点上,我有一些问题/疑问:

  • 某些代码无法解析,例如ByteBuffer,JSON ...

  • 我应该导入JSON-HTTP库吗?

  • 我不明白为什么无法解决ConnectivityManager,NetworkInfo。

编辑1

步骤1-应用程式专案

新模块-> Java库

应用程式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'])
}

项目摇篮

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

问题是您要在另一个子项目中移动代码,然后以不同的方式构建它。 要解决此问题,假设您使用的是Android Studio,请将新模块中需要的所有库移入模块Gradle.build文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM