導航:首頁 > 操作系統 > 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引用其他工程相關的資料

熱點內容
伺服器未響應怎麼解決手機 瀏覽:184
程序員回到古代 瀏覽:402
軟體合並一個文件夾 瀏覽:657
設置Android程序圖標 瀏覽:365
app哪個局 瀏覽:904
源碼編輯器中怎麼保存 瀏覽:463
python背景圖片代碼 瀏覽:448
3D卡片下載哪個App 瀏覽:532
如何用伺服器登錄微信 瀏覽:841
html5移動開發pdf下載 瀏覽:525
如何查看png圖片是否加密 瀏覽:821
php遞歸例子 瀏覽:190
伺服器參數配置未響應是什麼意思 瀏覽:603
pythonchardet模塊 瀏覽:751
添加gm命令 瀏覽:662
rsa加密碼亂碼 瀏覽:758
網站伺服器需要租什麼 瀏覽:999
c語言常用排序演算法 瀏覽:824
pythonhtml文件上傳 瀏覽:525
dosat命令執行exe 瀏覽:95