我可以使用依赖于AAR
的Android APK
(lib1)中的资源(字符串,资源,drawable)吗? lib1依赖的传递AAR
(lib2)中的资源怎么样?
答案 0 :(得分:0)
是
使用Android Archetypes我创建了一个android-with-test
项目,然后在其下面创建了两个android-library-quickstarts
项目。我不得不改变android-library-quickstart
项目'包装从apklib
到aar
。然后,我使lib1依赖于lib2,并使我的apk依赖于lib1。
我构建了一个Activity
直接消耗了来自两个库的布局中的资源(来自res/drawable
的图像,来自assets/fonts
的字体和来自values/strings.xml
的字符串)。尽管lib2是一个传递依赖,但我可以使用它的资源。
<强> activity_main.xml中强>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/library_1_string" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/library_2_string"/>
<TextView
android:id="@+id/library2_via_library1_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/library1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/library2" />
<TextView
android:id="@+id/library1_font_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="library1.ttf"/>
<TextView
android:id="@+id/library2_font_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="library2.ttf"/>
</LinearLayout>
<强> HelloAndroidActivity.java 强> 公共类HelloAndroidActivity扩展了Activity {
/**
* Called when the activity is first created.
* @param savedInstanceState If the activity is being re-initialized after
* previously being shut down then this Bundle contains the data it most
* recently supplied in onSaveInstanceState(Bundle). <b>Note: Otherwise it is null.</b>
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView library2ViaLibrary1TextView = (TextView) findViewById(R.id.library2_via_library1_text_view);
library2ViaLibrary1TextView.setText(Library1.getLibrary2String(this));
TextView library1FontTextView = (TextView) findViewById(R.id.library1_font_text_view);
library1FontTextView.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/library1.ttf"));
TextView library2FontTextView = (TextView) findViewById(R.id.library2_font_text_view);
library2FontTextView.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/library2.ttf"));
}
}