一个月前,我已经把我的项目移到了Android,我很高兴我这么做了,尽管我需要切换到一个新的(更强大的)构建系统(gradle)。在Eclipse中,我可能知道一件事,但我现在不知道如何实现,那就是修补支持库。我知道这听起来不像是一个很好的实践,但是有几个代码行让我抓狂,解决方案就是简单地修改它来解决我的问题。
我试图修改sdk的".\extras\android\m2repository\com\android\support“目录中的代码,但这似乎并不影响真正用于编译的代码。
知道怎么做到这一点吗?
编辑:
我试图在我的项目中创建一个模块"SupportLibraryV4“,当我尝试构建它时,这就是gradle告诉我的:
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令人印象深刻!
发布于 2014-01-17 08:57:36
Android没有构建支持库所需的所有文件。您需要从https://android.googlesource.com签出其他存储库。
请将目录结构保持在android存储库中。
现在,您可以更改支持库中的任何代码。如果需要更改api v.4的支持库,请在"platform\frameworks\ support \v4“中进行更改。要构建修补版本的支持库,请使用gradle和next命令:
platform\frameworks\support\v4\gradle clean jar结果jar可以在"platform\out\host\gradle\frameworks\support\v4\libs\".中找到将其放到项目的libs文件夹中,并添加build.gradle文件。
发布于 2016-10-15 13:20:22
使用捆绑的gradle包装器而不是系统的gradle安装更新了2016年Linux和OS的答案:
从https://android.googlesource.com中签出以下存储库并保持目录结构:
修改库中的文件:
platform/frameworks/support/中的文件Build AAR
cd platform/frameworks/support./gradlew jarReleaseplatform/out/host/gradle/frameworks/support/<module>/build/outputs/aar/中。添加到项目
libs/旁边创建一个build.gradle文件夹repositories{ flatDir{ dirs 'libs' } }中libs/dependencies { compile(name:'my_custom_supportlib_module', ext:'aar') }模块已经在项目中
当您修补其他模块所依赖的支持库模块时,您将在构建中使用它两次,从而导致错误。可以通过排除原始依赖项来避免这种情况。
例如,如果修补recyclerview-v7并添加
dependencies {
compile(name:'recyclerview-v7-release', ext:'aar')
}你必须把这种依赖排除在外。变化
compile "com.android.support:design:24.2.1"至
compile("com.android.support:design:24.2.1") {
exclude group: 'com.android.support', module: 'recyclerview-v7'
}对于所有依赖于修补模块的模块。
发布于 2013-12-10 21:03:13
修补SupportLib并将其手动添加为jar:
https://stackoverflow.com/questions/20474058
复制相似问题