How to create Library Project in Android Studio with Resource
<p>I am trying to create library project and used library code and resource to my other application, I can successfully get library activity or method which was not using any resource, but getting error when I try to use resource in activity or any method.</p>

<p>Here is my code.</p>

<pre><code>package com.dhl.lib;
import android.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;

public class AdditionActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        initUI();
    }

    private void initUI() {
        LinearLayout linearLayout = new LinearLayout(this);
        linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
        linearLayout.setOrientation(LinearLayout.VERTICAL);

        final EditText edtFirst = new EditText(this);
        edtFirst.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        edtFirst.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);

        final EditText edtSecond = new EditText(this);
        edtFirst.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        edtFirst.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);

        Button btn = new Button(this);
        btn.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        btn.setText("Add");

    btn.setBackground(getResources().getDrawable(R.mipmap.ic_launcher));
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(AdditionActivity.this, "==&gt; " + (Integer.parseInt(edtFirst.getText().toString().trim()) + Integer.parseInt(edtSecond.getText().toString().trim())), Toast.LENGTH_SHORT).show();
            }
        });

        linearLayout.addView(edtFirst);
        linearLayout.addView(edtSecond);

        linearLayout.addView(btn);
        setContentView(linearLayout);
    }

    @Override
    public void onClick(View v) {

    }
}
</code></pre>

<p><strong>Here another class which used resource</strong></p>

<pre><code> package com.dhl.lib;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

public class About {
    public static void show(Activity activity, String aboutText,
                            String okButtonText) {
        String versionNumber = "unknown";
        Drawable icon = null;
        String appName = "unknown";

        View about;
        TextView tvAbout;
        try {
            LayoutInflater inflater = activity.getLayoutInflater();
            about = inflater.inflate(R.layout.about, null);
            tvAbout = (TextView) about.findViewById(R.id.ca_tutortutor_aboutText);
        } catch (InflateException e) {
            about = tvAbout = new TextView(activity);
        }
        tvAbout.setText(Html.fromHtml(aboutText));
        tvAbout.setMovementMethod(LinkMovementMethod.getInstance());
        new AlertDialog.Builder(activity)
                .setTitle(appName + " " + versionNumber)
                .setIcon(icon)
                .setPositiveButton(okButtonText, null)
                .setView(about)
                .show();
    }
}
</code></pre>

<p>** XML Resource of About.xml **</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;scrollview xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/ca_tutortutor_aboutView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context="com.dhl.lib.About"&gt;

    &lt;linearlayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        android:padding="5dp"&gt;

        &lt;textview
            android:id="@+id/ca_tutortutor_aboutText"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"&gt;&lt;/textview&gt;
    &lt;/linearlayout&gt;
&lt;/scrollview&gt;
</code></pre>

<p>** Manifest of Lib Project **</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.dhl.lib"&gt;

    &lt;application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"&gt;
        &lt;activity android:name=".AdditionActivity"&gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;

                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
    &lt;/application&gt;

&lt;/manifest&gt;
</code></pre>

<p>** app build.gradle **</p>

<pre><code>apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
}
</code></pre>

<p>From that lib I can successfully get access of AdditionActivity on my Project but When I try to access About, getting error of java.lang.NoClassDefFoundError: Failed resolution of: Lcom/dhl/lib/R$layout;</p>

<p>Where I made mistake ? I can't found that point. </p>

<p>Here Is my Application app build.gradle which used library project</p>

<pre><code>apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.addtion.lib"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    provided files('libs/addition.jar')
}
</code></pre>

<p>** Application Main Activity Class **</p>

<pre><code>public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button btn = (Button) findViewById(R.id.btn_callAdd);
        btn.setText("Call Addition Activity");
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, AdditionActivity.class));
            }
        });


        ((Button) findViewById(R.id.btn_callAlert)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                About.show(MainActivity.this, "Hello From Application", "Ok");
            }
        });
    }
}
</code></pre>