android - Activity Class cannot be found in AAR file java.lang.NoClassDefFoundError -


i have created android library, contains activity class uses open camera intent, library works perfect excepts part invokes activity appear on screen , app crashes throwing following errors

suppressed: java.lang.classnotfoundexception: com.me.scanner.scannerviewactivity             @ java.lang.class.classforname(native method)             @ java.lang.bootclassloader.findclass(classloader.java:781)             @ java.lang.bootclassloader.loadclass(classloader.java:841)             @ java.lang.classloader.loadclass(classloader.java:504)                     ... 14 more          caused by: java.lang.noclassdeffounderror: class not found using boot class loader; no stack trace available 

following build.gradle file of other project use 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 module project,

    compile project(':scannercontrol') 

    but not when using aar in project

  • i have tried , without { transitive = true; }, no change

  • i have rename aar file scanner.aar
  • i have taken aar file form /[library-project]/build/outputs/aar/scanner-release.aar

update1 - 2017-09-14

the activity scannerviewactivity part of library, how been called 1 of 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 instance of android.app.application , not of activity

update2 - 2017-09-14

fortunately after roaming 2 days on google come across answer of question class not found in aar. have added dependencies of library project , able run aar not solution of issue,

following flow , issue i'm facing

  • i'm developing sandbox version of library communicates specific barcode scanner hardware, since developer doesn't have hardware use sandbox version of library allow developer use device camera barcode scanner,

  • we want developer extract aar files scanner.aar , scanner-sandbox.aar provided sdk , use either of them

  • we don't want developer add dependency .gradle file if want run sandbox version of library,

  • following dependency being used simulate device camera barcode scanner

    compile 'me.dm7.barcodescanner:zxing:1.9.8' 

the updated question is

what possible way distribute aar file without publishing them repository maven repository , dependencies of library installed when developer syncs .gradle file

zeeshan

i have faced same issue did lot of research & fixed helps you

creating .aar file project:

  1. for library module, .aar file automatically created android studio. project resource file or libraries, .aar file can generated mentioned in next steps.
  2. check plugin. should in follows, change library if in application, apply plugin: 'com.android.library'
  3. open open right border gradle bar , go “your project”->tasks->build , double click on assemblerelease. on building project, find 2 .aar files(app-debug.aar , app-release.aar) inside app/build/outputs/aar/ directory. using .aar file in project:
  4. get “app-release.aar” file , paste in libs folder of project. if libs folder not present, create directory named “libs” inside app directory.

  5. add following app gradle file, repositories { flatdir { dirs 'libs' } } dependencies { compile(name:'app-release', ext:'aar') }

  6. on sync, project ready use library files. note : .aar gradle dependencies has added manually in project app gradle example:below

assumption of errors:

system.err: java.lang.noclassdeffounderror:

solution:





.aar gradle dependencies has added manually in project app gradle


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -