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
Although I don't know the root cause, you can try this solution: in your app project, define an activity extends from ScannerViewActivity, and declare it in AndroidManifest.xml.
class MyScannerViewActivity extends ScannerViewActivity {
// do nothing or something you want
}
Then you should start MyScannerViewActivity instead of ScannerViewActivity by intent.
The answer for your "Update2 - 2017-09-14" - can simply build a fat aar file. which will contain all the dependencies, one thing which you may have to handle is conflict in dependencies sometime may create a issue. also the size of the fat aar may be huge. so give try.
The cause of the problem is that the class ScannerViewActivity
is called inside one of your AAR as a dependency like:
apply plugin: 'com.android.library'
android{...}
dependencies {
compile 'com.me.scanner:otherscanner@aar' //library which contains ScannerViewActivity
}
but when you use a aar (transitive won't add this aar dependencies !), you have to add the other dependency such as:
dependencies {
...
compile ('com.me.app:scanner@aar')// remove{ transitive = true; }
compile ('com.me.scanner:otherscanner@aar')
...
}
zeeshan
I have faced same issue i did lot of research & i fixed hopefully it helps you
Creating .aar file for a project:
- For a library module, .aar file is automatically created by Android Studio. For a project with the any resource file or with the libraries, .aar file can be generated as mentioned in next steps.
- Check the plugin. It should be in as follows, change to library if it is in application, apply plugin: 'com.android.library'
- Open the open right border gradle bar and go to “your project”->Tasks->build and then double click on the assembleRelease. On Building the project, You will find the two .aar files(app-debug.aar and app-release.aar) inside app/build/outputs/aar/ directory. Using .aar file in your project:
Get the “app-release.aar” file and paste it in the libs folder of your project. If libs folder is not present, create a directory named “libs” inside app directory.
Add the following to the app gradle file, repositories { flatDir { dirs 'libs' } } dependencies { compile(name:'app-release', ext:'aar') }
- On sync, your project is ready to use the library files. Note : .aar gradle dependencies has to be added manually in your project app gradle Example:below
Assumption of errors: System.err: java.lang.NoClassDefFoundError:
Solution:
.aar gradle dependencies has to be added manually in your project app gradle
There are 3 ways to distribute your library:
Creating a local maven library then distribute the generated aar.
You can create a local aar by using Gradle Android Maven plugin. How to make it:
a. Add the plugin classpath to root build.gradle
:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
allprojects {
repositories {
jcenter()
}
}
b. Set the maven plugin, and add group and version name to library build.gradle:
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
group = 'com.your.packagename'
version = '1.0.0'
ext.versionCode = 1000
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 9
targetSdkVersion 25
versionCode versionCode
versionName version
}
buildTypes {
...
}
}
dependencies {
...
}
c. Set the artifactId is set in settings.gradle:
rootProject.name = 'yourlibraryname'
d. Build and install the library to your local maven.
You can run ./gradlew
install on project folder or use
Gradle -> YourLibrary -> Other -> Install from Android Studio (on the right side of Android Studio)
e. Use the installed library directly to your project.
You can use the library by adding mavenLocal()
to your root build.gradle
allprojects {
repositories {
jcenter()
mavenLocal() // for local maven.
}
}
Then add the dependency to the project:
compile 'com.your.packagename:modulename:1.0.0'
Or you can copy the generated .aar from local maven path. In Linux, you can get it from /your/userpath/.m2/repository/
or ~/.m2/repository/
Use the same technique in number 1, but make the local maven path for each developer computer pointing to the ~/.m2/repository/
central.
Use a private maven repository. You can use JFrog Artifactory oss or Nexus Repository OSS
Can you try as below?
Instant runs sometimes cause an issue due to caching.
Edit: For adding local AAR. You can follow the answer as mentioned here