首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Android的修补程序支持库

问使用Android的修补程序支持库
EN

Stack Overflow用户
提问于 2013-12-09 15:16:57
回答 4查看 2.2K关注 0票数 2

一个月前,我已经把我的项目移到了Android,我很高兴我这么做了,尽管我需要切换到一个新的(更强大的)构建系统(gradle)。在Eclipse中,我可能知道一件事,但我现在不知道如何实现,那就是修补支持库。我知道这听起来不像是一个很好的实践,但是有几个代码行让我抓狂,解决方案就是简单地修改它来解决我的问题。

我试图修改sdk的".\extras\android\m2repository\com\android\support“目录中的代码,但这似乎并不影响真正用于编译的代码。

知道怎么做到这一点吗?

编辑:

我试图在我的项目中创建一个模块"SupportLibraryV4“,当我尝试构建它时,这就是gradle告诉我的:

代码语言:javascript
复制
Error Code:
    1
Output:

    trouble processing "java/android/support/v4/R$anim.class":

    Ill-advised or mistaken usage of a core class (java.* or javax.*)
    when not building a core library.

    This is often due to inadvertently including a core library file
    in your application's project, when using an IDE (such as
    Eclipse). If you are sure you're not intentionally defining a
    core class, then this is the most likely explanation of what's
    going on.

    However, you might actually be trying to define a class in a core
    namespace, the source of which you may have taken, for example,
    from a non-Android virtual machine project. This will most
    assuredly not work. At a minimum, it jeopardizes the
    compatibility of your app with future versions of the platform.
    It is also often of questionable legality.

    If you really intend to build a core library -- which is only
    appropriate as part of creating a full virtual machine
    distribution, as opposed to compiling an application -- then use
    the "--core-library" option to suppress this error message.

    If you go ahead and use "--core-library" but are in fact
    building an application, then be forewarned that your application
    will still fail to build or run, at some point. Please be
    prepared for angry customers who find, for example, that your
    application ceases to function once they upgrade their operating
    system. You will be to blame for this problem.

    If you are legitimately using some code that happens to be in a
    core package, then the easiest safe alternative you have is to
    repackage that code. That is, move the classes in question into
    your own package namespace. This means that they will never be in
    conflict with core system classes. JarJar is a tool that may help
    you in this endeavor. If you find that you cannot do this, then
    that is an indication that the path you are on will ultimately
    lead to pain, suffering, grief, and lamentation.

    1 error; aborting

令人印象深刻!

EN

回答 4

Stack Overflow用户

发布于 2014-01-17 08:57:36

Android没有构建支持库所需的所有文件。您需要从https://android.googlesource.com签出其他存储库。

  • 平台/框架/支助
  • 平台/预构建/分级-插件
  • 平台/prebuilts/maven_repo/android
  • 平台/预构建/sdk
  • 平台/预构建/工具

请将目录结构保持在android存储库中。

现在,您可以更改支持库中的任何代码。如果需要更改api v.4的支持库,请在"platform\frameworks\ support \v4“中进行更改。要构建修补版本的支持库,请使用gradle和next命令:

代码语言:javascript
复制
platform\frameworks\support\v4\gradle clean jar

结果jar可以在"platform\out\host\gradle\frameworks\support\v4\libs\".中找到将其放到项目的libs文件夹中,并添加build.gradle文件。

票数 3
EN

Stack Overflow用户

发布于 2016-10-15 13:20:22

使用捆绑的gradle包装器而不是系统的gradle安装更新了2016年Linux和OS的答案:

从https://android.googlesource.com中签出以下存储库并保持目录结构:

  • 平台/框架/支助
  • 平台/预构建/分级-插件
  • 平台/prebuilts/maven_repo/android
  • 平台/预构建/sdk
  • 平台/预构建/工具
  • 平台/工具/外部/分级

修改库中的文件:

  • 更改platform/frameworks/support/中的文件

Build AAR

  • cd platform/frameworks/support
  • ./gradlew jarRelease
  • 生成的.aar位于platform/out/host/gradle/frameworks/support/<module>/build/outputs/aar/中。

添加到项目

  • 在应用程序的libs/旁边创建一个build.gradle文件夹
  • 将libs文件夹添加到build.gradle:repositories{ flatDir{ dirs 'libs' } }中
  • 将.aar文件复制到libs/
  • 将aar添加到build.gradle中的依赖项部分,例如:dependencies { compile(name:'my_custom_supportlib_module', ext:'aar') }

模块已经在项目中

当您修补其他模块所依赖的支持库模块时,您将在构建中使用它两次,从而导致错误。可以通过排除原始依赖项来避免这种情况。

例如,如果修补recyclerview-v7并添加

代码语言:javascript
复制
dependencies {
    compile(name:'recyclerview-v7-release', ext:'aar')
}

你必须把这种依赖排除在外。变化

代码语言:javascript
复制
compile "com.android.support:design:24.2.1"

至

代码语言:javascript
复制
compile("com.android.support:design:24.2.1") {
    exclude group: 'com.android.support', module: 'recyclerview-v7'
}

对于所有依赖于修补模块的模块。

票数 1
EN

Stack Overflow用户

发布于 2013-12-10 21:03:13

修补SupportLib并将其手动添加为jar:

  • 将SupportLib jar放入libs文件夹
  • 右击它并点击'Add as library‘
  • 确保编译文件(‘libs/Supportlib.jar’)在您的build.gradle文件中
  • 做一个干净的构建

免责声明:Android Studio: Add jar as library?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20474058

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档