导航:首页 > 操作系统 > android引用其他工程

android引用其他工程

发布时间:2022-10-24 00:58:27

1. android中引用另一个工程, android.library.reference.1=../ 工程名

如果都可以用,那就是没区别,如果你是想问/和\\的区别的就是window系列系统,为了和unix系统体现出区别,而采用/表示目录的,最开始的系统是unix,他用的是\表示目录的。

2. 如何把一个android工程作为另外一个android工程的lib库

在实际使用中,我们可能会把一个android工程作为库,然后在另外一个android的工程中引用。实现的步骤如下: 1.将android工程设为库 选择工程右击选择“property”-Android选项下的library勾选“Is Library”。 2.在当前工程引用上面的工程的库 在当前工程目录下的文件“project.properties”里添加: android.library.reference.1=..\\xxx(工程目录) 这样就可以使用库工程的代码及资源的。 验证是否可以正常引用:可以到“property”-Android选项选项下的library有Reference中显示你所引用到的工程。

3. 如何把一个android工程作为另外一个android工程的lib库

一个思路是把工程A做成纯Jar包,这样其他的工程就可以直接引用了。 但是,如果在工程A中用了R.java中的引用,则无法打成jar包了。
原因是R.java是自动生成的,是动态的,每次编译都是不相同的。如果一定要做成jar包,就不能使用自动生成的R文件,用到资源时候就要写代码去获取。

另一个思路就是将工程A做成android library project。
设置工程A,右键->Properties->Android,将Is library项选中,然后Apply。
设置工程B,右键->Properties->Android,在Library中,点击Add按钮,将A工程加入,然后Apply。
此时在B中就引入了A中的资源和代码,这些资源和代码都可以直接调用。
需要注意的是,因为A已经不再是一个完整的Android应用,而是一个类库工程,所以有一些内容还需要在B中配置一下。
比如A中有lib库引用,则B中也要加入该lib库;比如A中的AndroidManifest.xml文件的内容,在B的AndroidManifest.xml文件中也要相应加上。。。
分类: Android

4. 如何在一个android工程中调用另一个android工程的代码和资源啊

现在已经有了一个Android工程A。我们想扩展A的功能,但是不想在A的基础上做开发,于是新建了另外一个Android工程B,想在B中引用A。

1. 把工程A做成纯Jar包,这样其他的工程就可以直接引用了。

但是,如果在工程A中用了R.java中的引用,则无法打成jar包了。原因是R.java是自动生成的,是动态的,每次编译都是不相同的。如果一定要做成jar包,就不能使用自动生成的R文件,用到资源时候就要写代码去获取。

有时会报错:Conversion to Dalvik format failed with error 1

可能是多层包文件重复导入,冲突。。。

这时可以试试方法2

 

2.将工程A做成android library project。

设置工程A,右键->Properties->Android,将Is library项选中,然后Apply。设置工程B,右键->Properties->Android,在Library中,点击Add按钮,将A工程加入,然后Apply。此时在B中就引入了A中的资源和代码,这些资源和代码都可以直接调用。需要注意的是,因为A已经不再是一个完整的Android应用,而是一个类库工程,所以有一些内容还需要在B中配置一下。比如A中有lib库引用,则B中也要加入该lib库;比如A中的AndroidManifest.xml文件的内容,在B的AndroidManifest.xml文件中也要相应加上。。。
如果不需要引用A工程的资源文件,同样只需得到jar文件,
设置工程A,右键->Properties->Android,将Is library项选中,然后Apply。在A工程的bin目录下能得到一个jar文件,可以到B工程中的libs目录下直接引用。
 
如果能用jar当然最好,但是jar文件不能把res目录下的资源打包进去,所以才出现lib工程。

创建和使用Android library工程
 

摘要: 创建library供多个工程共享代码、资源是非常常见的需求,网上这种资料非常少,基本上都是讲创建java工程,然后export,这种方式缺点非常多,大家可以自己google一下。本文着重介绍如何创建Android library,并且在 ...
创建library供多个工程共享代码、资源是非常常见的需求,网上这种资料非常少,基本上都是讲创建java工程,然后export,这种方式缺点非常多,大家可以自己google一下。
本文着重介绍如何创建Android library,并且在工程中使用此library提供的资源,具体步骤如下:
1. 创建一个Android工程,命名为MyLib
2. 进入工程设置选中Is Library

3. 创建另一个Android工程,命名为MyProj
4. 进入工程设置,添加MyLib

5. 在MyProj的AndroidManifest.xml中加入对library中activity的引用
<activity android:name="net.devdiv.mylib.MyLib" />
6. 由于编译后library中的资源和引用它的project资源是合并在一起的,为了避免重名问题,需要对library中资源进行重命名
1). 把main.xml改为mylib.xml,同时修改MyLib.java代码setContentView(R.layout.mylib);
2). strings.xml修改为
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="mylibhello">String fetched from lib!</string>
    <string name="mylib_app_name">MyLib</string>
</resources>
7. 在MyProj中引用MyLib的资源
package net.devdiv.myproj;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import net.devdiv.mylib.*;
import android.content.Intent;

public class MyProj extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView tv = (TextView)findViewById(R.id.myprojtext);
       tv.setText(R.string.mylibhello);
        
        Intent it = new Intent(this, MyLib.class);
        startActivity(it);
    }
}

5. Android如何引用其他工程

按如下方法设置: 1. 假设要引用的android工程叫LibProject,引入到的工程叫MainProject; 2. 设置LibProject,右键-Properties-Android,将Is library项选中,然后Apply; 3. 设置MainProject,右键--Properties-Android, 在Library中,点击Add按钮,将LibProject工程加入,Apply即可。 设置完成后,在MainProject工程中能看到LibProject的代码等资源都已经引入进来。

6. Android如何引用其他工程

Referencing a library project If you are developing an application and want to include the shared code or resources from a library project, you can do so easily by adding a reference to the library project in the application project's Properties.To add a reference to a library project, follow these steps:In the Package Explorer, right-click the dependent project and select Properties. In the Properties window, select the "Android" properties group at left and locate the Library properties at right. Click Add to open the Project Selection dialog. From the list of available library projects, select a project and click OK. When the dialog closes, click Apply in the Properties window. Click OK to close the Properties window.As soon as the Properties dialog closes, Eclipse rebuilds the project, including the contents of the library project.Figure 2 shows the Properties dialog that lets you add library references and move them up and down in priority.Figure 2. Adding a reference to a library project in the properties of an application project.If you are adding references to multiple libraries, note that you can set their relative priority (and merge order) by selecting a library and using the Up and Down controls. The tools merge the referenced libraries with your application starting from lowest priority (bottom of the list) to highest (top of the list). If more than one library defines the same resource ID, the tools select the resource from the library with higher priority. The application itself has highest priority and its resources are always used in preference to identical resource IDs defined in libraries.Declaring library components in the the manifest fileIn the manifest file of the application project, you must add declarations of all components that the application will use that are imported from a library project. For example, you must declare any <activity>, <service>, <receiver>, <provider>, and so on, as well as<permission>, <uses-library>, and similar elements.Declarations should reference the library components by their fully-qualified package names, where appropriate.For example, the TicTacToeMain example application declares the library Activity GameActivity like this:<manifest> ... <application> ... <activityandroid:name="com.example.android.tictactoe.library.GameActivity"/> ... </application></manifest>按如下方法设置:1. 假设要引用的android工程叫LibProject,引入到的工程叫MainProject;2. 设置LibProject,右键->Properties->Android,将Is library项选中,然后Apply;3. 设置MainProject,右键->->Properties->Android, 在Library中,点击Add按钮,将LibProject工程加入,Apply即可。

7. android studio怎么引入另一个工程

android studio导入工程的步骤:
1、在Android Studio 中,首先关掉当前的打开的项目。
2、在欢迎界面,点击Import Project(注:也是可以直接在菜单选择Import project的)。
3、选中Eclipse中导出的项目,展开目录,点击build.gradle文件,然后OK。
4、在之后的弹出对话框中,会要求选择Gradle的配置,选中Use gradle wrapper.(注:也可以自定义本机装的Gradle)。

注意:如果没有Grade build文件,也是可以将普通的安卓项目导入到Android Studio中,它会用现有的Ant build.但为了更好地使用之后的功能和充分使用构建变量,还是强烈地建议先从ADT插件中生成Gradle文件再导入Android Studio。

8. 如何一个android工程作为另外一个android工程的lib

1. 创建一个Android工程,命名为MyLib
2. 进入工程设置选中Is Library

3. 创建另一个Android工程,命名为MyProj
4. 进入工程设置,添加MyLib

5. 在MyProj的AndroidManifest.xml中加入对library中activity的引用
<activity android:name="net.devdiv.mylib.MyLib" />
6. 由于编译后library中的资源和引用它的project资源是合并在一起的,为了避免重名问题,需要对library中资源进行重命名
1). 把main.xml改为mylib.xml,同时修改MyLib.java代码setContentView(R.layout.mylib);
2). strings.xml修改为
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="mylibhello">String fetched from lib!</string>
<string name="mylib_app_name">MyLib</string>
</resources>

9. android 导入的第三方工程怎样使用原工程

首先你引用的项目必须是一个Library

项目上点击右键-->properties-->android

然后在你的项目上右键-->properties-->android-->add选择导入的Library

查看java Build Path

引入成功

但如果你引用的第三方library导入了第三方jar包,你就必须也导入它引用的jar包

错误

1.java.lang.NoClassDefFoundError

如果报了这个错误可能是你没有导入library引用的jar包 或者导入错误

最好是把library的jar包复制到你的libs目录下在导入

2.Jar
mismatch! Fix your dependencies

你的项目和第三方library引用的android-support-v4.jar不是同一个版本

有可能你的项目用的SDK的level是19 别人的是17就会导致这个错误

你可以吧别的项目里的android-support-v4.jar包同时导入到这两个项目里

让两个项目的android-support-v4.jar包保持统一

10. android studio 怎么导入别的工程

新版Android Studio/IntelliJ IDEA可以直接导入eclipse项目,不再推荐使用eclipse导出gradle的方式

2
启动Android Studio/IntelliJ IDEA,
选择 import project

3
选择eclipse 项目

4
选择 create project from existing sources或者 import project from external model

5
填写项目名字和存储路径

6
勾选需要导入的目录 默认就可,不用管

7
勾选需要导入的library
这里bin 文件夹下的jar不用勾选

8
再次检查

9
导入 android Manifest.xml文件点击finish就可完成导入

10
导入后的项目

11
进入libs 文件夹,将libs下的jar添加成库文件
1.选择要添加的jar
2.右键选择add as library
3.Level 选择 Mole library
4. Add to mole 选择你要添加到的mole

阅读全文

与android引用其他工程相关的资料

热点内容
文件夹侧面目录标签怎么制作 浏览:230
做程序员学什么 浏览:320
pdfeditor教程 浏览:880
fortran把文件放入文件夹 浏览:709
程序员1年经验不敢投简历 浏览:481
如何看电脑的源码 浏览:897
找工作app软件哪个好 浏览:96
信息管理网站源码 浏览:439
小说app哪个好免费 浏览:224
域名在线加密 浏览:146
软件编程西安交大 浏览:453
是不是串货的奶粉查不到溯源码的 浏览:825
北京dns服务器云主机 浏览:221
openldaplinux安装 浏览:23
java取月的最后一天 浏览:10
腾讯云服务器多久退款 浏览:949
微信广告植入系统源码 浏览:922
一年级语文上册pdf 浏览:315
好久不见app干什么用的 浏览:143
压缩包解压码对方可以更改吗 浏览:256