【问题标题】:Library for android, using android jarandroid库,使用android jar
【发布时间】:2016-01-30 17:16:22
【问题描述】:

我想创建一个使用 SharedPreferences 的库。现在要这样做,我需要有 android.jar 可供我使用。但是,由于我的项目永远不会独立运行,因此我非常怀疑将其作为一个成熟的 android 应用程序是否是正确的方法。

现在我有以下 build.gradle:

apply plugin: 'eclipse'
apply plugin: 'maven'

buildscript {
    repositories { 
        jcenter()
    }


    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
    }
}


apply plugin: 'android-library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    repositories {
        mavenCentral()
    }

    dependencies {
      compile fileTree(dir: 'libs', include: '*.jar')
      testCompile 'junit:junit:4.12'
      testCompile 'org.slf4j:slf4j-simple:1.6.1'

    }
}

还有如下错误:

FAILURE:构建失败并出现异常。

  • 出了什么问题:配置根项目“NetworkSynchronizer”时出现问题。

    java.io.FileNotFoundException: D:\Users\Beheerder\git\NetworkSynchronizer\src\main\AndroidManifest.xml (系统找不到指定的文件)

  • 尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。

这是正确的方法吗,我应该添加一个 AndroidManifest.xml,还是应该如何处理?

【问题讨论】:

    标签: java android gradle


    【解决方案1】:

    将 AndroidManifest 添加到您的库中:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="<YOUR_PACKAGE_HERE>">
    
        <application android:allowBackup="true"
                 android:label="@string/app_name">
    
        </application>
    </manifest>
    

    因为您使用的是 android-library 插件,所以这很正常。最后你会得到@aar 文件,而不是jar。祝你好运!

    【讨论】:

    • jar 库可以阅读here
    猜你喜欢
    • 1970-01-01
    • 2016-02-13
    • 2014-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-27
    • 2013-10-18
    相关资源
    最近更新 更多