如何分配可重复使用的Andr​​oid code在一个包? [英] How to distribute the android reusable code in a package?

查看:116
本文介绍了如何分配可重复使用的Andr​​oid code在一个包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一些可重复使用的Andr​​oid组件,它基本上是一个类。这个类有一些资源依赖例如一些巴可绘制一些XML布局等,所以这个类中引用的自动阵列生成的R file.I想在一个封装中像jar文件到其他开发人员在他们的应用分发本code。

I have developed some reusable android component which is basically a class . This class has some resource dependencies e.g. some png drawables, some xml layouts etc. So this class referenced the auto-generated R file.I would like to distribute this code in a single package like jar file to other developers for use in their applications.

我看了,唯一可行的办法是用我所有的资源,其他人都复制到自己的资源文件夹一起分发code(<一href="http://stackoverflow.com/questions/1995004/packaging-android-resource-files-within-a-distributable-jar-file/2825174#2825174">source).

I have read that the only possible solution is to distribute code together with all my resources, which others have to copy to their "res" folder (source).

所以,我创建了具有类文件(比如MyClass的是在包 com.xyz.android.app <​​/ code>)资源的JAR文件和并试图用这我的新的应用程序。

So I created a jar file having the class file (say MyClass which is in the package com.xyz.android.app) and resources and tried to use this in my new application.

所以我添加的jar文件到我的新的应用程序生成使用添加外部JAR在eclipse 选项,并复制了所有的资源,我的新应用程序的资源文件夹路径。 (Activity类说我的新的应用程序MainActivity是 com.abc.myapplication 包,只为的情况下,如果它可能有用)

So I added the jar file to my new applications build path using add external jars option in eclipse and copied all the resources to my new application's res folder. (The activity class say MainActivity of my new application is in com.abc.myapplication package, just for the case if it may helpful)

但是,当我运行这个新的应用程序有 java.lang.ClassCastException 在MyClass类。我试图调试应用程序,然后我发现,在MyClass类,有R解决不了的问题。

But when I run this new application there is java.lang.ClassCastException in the MyClass class. I tried to debug the application and then I found that in the MyClass class, there is "R cannot be resolved" problem.

然后,我改变MainActivity的包 com.xyz.android.app <​​/ code>(这是没有办法的办法,其他开发人员会很乐意这样做),但同样同样的问题

Then I changed MainActivity's package to com.xyz.android.app (which is not the way, other developers will be happy to do), But again the same problem.

不过,当我刚才复制的代码的Java文件,这样既MainActivity.java和MyClass.java在com.xyz.android.app包,那么应用程序运行正常。

But When I just copy the source java file such that both MainActivity.java and MyClass.java are in com.xyz.android.app package then application runs fine.

所以,如果我需要分发,这样其他用户不必理会这些包命名的东西, 我怎样才能做到这一点?请帮助!

So if I need to distribute such that other users need not to bother these package naming things, how can I accomplish this? Please help !!

修改

在的android.jar,也有一些资源。他们是如何在一个项目中引用?他们是如何在android的类中使用?还有a​​ndroid.R文件?

In android.jar, there are also some resources. How are they referenced in a project? How are they used in android classes? There is also android.R file?

难道不能做同样的事情,即要做出这样的android.jar jar文件为我的可重复使用的code?

Is it not possible to do the same thing i.e. to make jar file like android.jar for my reusable code?

推荐答案

由于尼克强指出,没有什么太大纳入项目管理这一点,目前的迹象表明,该SDK工具即将发生的变化可能只帮助位。

As Nic Strong noted, there is nothing much built into the project to manage this, and current indications are that the upcoming changes to the SDK tools may only help a bit.

我组织一些其他的工具,以帮助解决这个问题。我希望能够有开发者文档公布在几天之内。

I am organizing some other tools to help deal with this problem. I hope to have developer documentation published in a few days.

这篇关于如何分配可重复使用的Andr​​oid code在一个包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆