I have created an android library, it contains an Activity Class that uses to open camera intent, the library works perfect excepts for the part that invokes the Activity to appear over the screen and the app crashes throwing following errors
Suppressed: java.lang.ClassNotFoundException: com.me.scanner.ScannerViewActivity
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 14 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
Following is my build.gradle
file of other project that will use this library
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.me.app:gpio_lib@aar'
compile ('com.me.app:scanner@aar'){ transitive = true; }
testCompile 'junit:junit:4.12'
}
Please Note:
This library works perfectly as module project,
compile project(':scannercontrol')
but not when using it as
aar
in the projectI have tried with and without
{ transitive = true; }
, no change- I have rename my aar file to
scanner.aar
- I have taken the aar file form
/[library-project]/build/outputs/aar/scanner-release.aar
Update1 - 2017-09-14
The activity ScannerViewActivity
is part of my library, this is how it is been called from one of the library class
Intent scannerView = new Intent();
scannerView.putExtra(MESSAGE_RECEIVER, new MessageReceiver());
scannerView.setClass(context, ScannerViewActivity.class);
scannerView.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(scannerView);
this context
is the instance of android.app.Application
and not of any Activity
Update2 - 2017-09-14
Fortunately after roaming 2 days all over google I come across the answer of question Class not found in aar. I have added the dependencies of the library to the project and able to run it with aar
but this is not the solution of my issue,
Following is the flow and issue I'm currently facing
I'm developing a sandbox version of a library that communicates with a specific barcode scanner hardware, since the developer doesn't necessarily have the hardware they will use the sandbox version of the library that will allow developer to use their device camera as a barcode scanner,
We want the developer to extract the
AAR
filesscanner.aar
andscanner-sandbox.aar
from providedSDK
and use either of themWe don't want the developer to add extra dependency to their
.gradle
file if they want to run the sandbox version of the library,Following is the dependency that is being used to simulate device camera as a barcode scanner
compile 'me.dm7.barcodescanner:zxing:1.9.8'
The updated question is
What is the possible way to distribute an aar file without publishing them to any repository like maven repository and all dependencies of the library installed when developer syncs the .gradle
file