Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access to the resources of a library for Android?

I am trying to access a library that contains some strings and drawables. In my main project I add the library as a module. The problem is that when I want to reference in a layout to a string or a color resource, I can't. According to the guide of the API syntax, I use @[package.of.the.library]:type/resource_name, but this does not work.

I add an example of the layout that I use for testing:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mylibrary="http://schemas.android.com/apk/com.mylibrary.resources"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@mylibrary:string/testing_text" />
</LinearLayout>

I have tried using xmlns:mylibrary="http://schemas.android.com/apk/res-auto" instead of xmlns:mylibrary="http://schemas.android.com/apk/com.mylibrary.resources" but it doesn't work.

like image 663
Ander Acosta Avatar asked Dec 14 '25 00:12

Ander Acosta


2 Answers

You need to add compile project(":mylibrary") to your app build.gradle file dependencies.

dependencies {
    compile project(":mylibrary")
    ...rest of dependencies for project
}
like image 71
Joopkins Avatar answered Dec 16 '25 14:12

Joopkins


First add the module as dependency to main project build.gradle file

compile project(":module_name")

where module_name is name of module project

and then u can access string or color just like normal string and color

@string/testing_text
like image 29
JAAD Avatar answered Dec 16 '25 14:12

JAAD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!