Android Room Persistence Library not working inside library project - java

I'm developing an Android library, and want to use the new Android Room persistence library inside it. However, when launching I got this error :
Caused by: java.lang.RuntimeException: cannot find implementation for
MyLibraryName.Database.QSDatabase. QSDatabase_Impl does not exist
at android.arch.persistence.room.Room.getGeneratedImplementation(Room.java:90)
which means that the annotationProcessor is not generating the extra code during compilation.
Btw, everything is working fine when I put my #Database code inside the app module.
My gradle file (library module) :
apply plugin: 'com.android.library'
apply plugin: 'groovyx.android'
buildscript {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:1.1.0'
}
}
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '25.3.0'
}
}
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { java.srcDirs = ['src/main/java', 'src/main/groovy'] } }
}
dependencies {
// google Room persistence library
compile "android.arch.persistence.room:runtime:1.0.0-alpha1"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
{
exclude group: 'com.android.support', module: 'support-annotations'
})
// google location service
compile 'com.google.android.gms:play-services-location:10.2.4'
androidTestCompile 'junit:junit:4.12'
// Http
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.8.0'
compile 'com.squareup.retrofit2:converter-scalars:2.1.0'
// groovy
compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.4.4'
}

This can happen when you use annotationProcessor in a kotlin project.
if so, do these
apply plugin: 'kotlin-kapt'
and use kapt instead of annotationProcessor

#stevenwood It seems you're right about groovy/
I had the same project structure. But in my case, I had no real Groovy code inside groovy/. Only plain old Java code. Hence, perhaps it was easier for me to get the project working again by making the following changes
Removing / commenting-out classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.8' from the project's build.gradle
Removing / commenting-out apply plugin: 'groovyx.grooid.groovy-android' from the module's build.gradle
git mv groovy/ java/
Thereafter at least, I stopped getting the missing Database_Impl message from Room.

Related

Using Java 8 in Android Studio 2.3.2 does not work

I have an APi that was built for Java 8.
Currently, I have Android Studio 2.3.2 on Ubuntu and to be honest, I hesitate to update it.
I used Jack and set target and source compatibility to Java Version 1.8.
When I am in debug modus, everything works as expected.
But when I want to create a signed apk I get errors like these:
Error:Lambda coming from jar file need their interfaces on the classpath to be compiled, unknown interfaces are java.util.function.Function
I tried this one here https://github.com/evant/gradle-retrolambda
But checking the java version with "java --version" tells me that I have Java 1.8 already installed on my machine.
What can I do? I don't want to update to Android 3+
This is my gradle (app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.project.myapp"
minSdkVersion 17
targetSdkVersion 26
versionCode 12
versionName "1.055"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled = true
jackOptions {
enabled true
}
}
buildTypes {
debug {
resValue "string", "google_maps_api_key", GoogleMapDebug
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue "string", "google_maps_api_key", GoogleMapRelease
}
compileOptions{
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/asset/'] } }
}
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:design:26.1.0'
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:cardview-v7:26.3.1'
compile 'com.android.support:support-v4:26.3.1'
compile 'com.google.android.gms:play-services-location:12.0.+'
compile 'com.google.android.gms:play-services-maps:12.0.+'
compile 'com.baoyz.swipemenulistview:library:1.3.0'
compile 'com.patrickpissurno:ripple-effect:1.3.1'
compile 'com.google.firebase:firebase-core:12.0.1'
compile 'com.google.firebase:firebase-messaging:12.0.1'
compile 'com.firebase:firebase-jobdispatcher:0.5.2'
compile 'com.firebaseui:firebase-ui-database:3.3.0'
compile 'com.google.firebase:firebase-auth:12.0.1'
compile 'com.firebaseui:firebase-ui:3.3.0'
compile 'com.firebaseui:firebase-ui-auth:3.3.0'
compile 'com.squareup.picasso:picasso:2.71828'
compile 'com.github.medyo:android-about-page:1.2.5'
compile 'de.codengine:tankerkoenig-api-client:1.0'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
This is the gradle (project):
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
jcenter()
maven{
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
def keystorePropertiesFile = rootProject.file("gradle.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

Switching Android module from library to application results in "Unable to resolve dependency for :app#debug/compileClasspath"/

I have an android app I want to import to my project as a module. The module syncs and compiles fine with apply plugin: 'com.android.application' However, there are classes from the module that I want to use in my project. To do this, it seems like I need to switch the gradle for the module to read apply plugin: 'com.android.library' as per this question. However, changing the module from an application to a library results in the following error log:
Unable to resolve dependency for ':app#debug/compileClasspath': Failed to transform file 'OCRTest-release.aar' to match attributes {artifactType=android-exploded-aar} using transform ExtractAarTransform
Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Failed to transform file 'OCRTest-release.aar' to match attributes {artifactType=android-exploded-aar} using transform ExtractAarTransform
...
Unable to resolve dependency for ':app#releaseUnitTest/compileClasspath': Failed to transform file 'OCRTest-release.aar' to match attributes {artifactType=android-exploded-aar} using transform ExtractAarTransform
So far I have tried invalidating caches and restarting Android Studio, as that was a common suggestion. I have also seen it suggested to delete the .gradle file altogether. Is that safe to do? Also, the main thing I want to do is be able to use Java classes from the module in my app's activities. If there is a better way to go about doing this, let me know.
Here is the code for my .gradle files.
settings.gradle:
include ':app'
include ':OCRTest'
build.gradle(Project):
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle(Module: OCRTest): This is the module that contains classes I want to use in my app
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
minSdkVersion 15
targetSdkVersion 27
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard.cfg'
}
}
}
dependencies {
implementation 'com.rmtheis:tess-two:9.0.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
}
build.gradle(Module: app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "org.noblis.thirdeye"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
matchingFallbacks = ['debug']
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.rmtheis:tess-two:9.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(path: ':OCRTest', configuration: 'default')
}
Remove the following line from build.gradle(Module:app):
implementation project(path: ':OCRTest', configuration: 'default')
Sync Gradle files.
Replace settings.gradle with this line:
include ':app', ':OCRTest'
Sync Gradle files again.
Now goto Project Structure>Add Module dependency and add module.
Hope this helps :)

Error: more than one library with package name 'com.google.android.gms.license'

Today, I opened Android Studio, then I get this error. Yesterday, there was a no problem such that!
Error:Execution failed for task ':app:processDebugResources'.
Error: more than one library with package name 'com.google.android.gms.license'
com.google.android.gms:play-services-xxx libraries was
11.8.0
Onesignal library was
'com.onesignal:OneSignal:[3.6.2, 3.99.99]'
Then I changed them to latest version.
Now App/Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "xxx.xxx.xxx"
minSdkVersion 15
targetSdkVersion 24
versionCode 10
versionName 'x.x.x'
manifestPlaceholders = [onesignal_app_id: "xxxxx-xx-xxx",
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: "XXX"]
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
repositories {
maven { url 'https://maven.google.com' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.mcxiaoke.volley:library:1.0.18'
compile 'com.github.chrisbanes.photoview:library:1.2.3'
compile 'com.facebook.android:facebook-android-sdk:4.0.1'
compile 'com.google.android.gms:play-services-ads:12.0.0'
//compile 'com.google.android.gms:play-services-ads:11.2.2'
compile 'com.pkmmte.view:circularimageview:1.1'
compile 'com.melnykov:floatingactionbutton:1.3.0'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
//compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:appcompat-v7:27.1.0'
compile 'com.android.support:cardview-v7:27.1.0'
compile 'com.android.support:recyclerview-v7:27.1.0'
compile 'com.android.support:design:27.1.0'
compile 'com.balysv:material-ripple:1.0.2'
compile "com.google.firebase:firebase-messaging:12.0.0"
compile 'com.github.hotchemi:android-rate:1.0.1'
compile 'com.onesignal:OneSignal:[3.7.1, 3.99.99]'
compile 'com.google.android.gms:play-services-analytics:12.0.0'
}
apply plugin: 'com.google.gms.google-services'
Project/Gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.1.1'
// classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
But I am still getting same error that stated above. How can I solve this problem? Why did this problem occur Today when there was no problem, yesterday?
This probably because the play services version is not in the range defined for
OneSignal:[3.7.1, 3.99.99] which is (you can see it at this commit):
// Limit upper number (exclusive) to prevent untested versions
static def versionGroupOverrides = [
'com.google.android.gms': '[10.2.1, 11.7.0)',
'com.android.support': '[26.0.0, 27.1.0)'
]
So, try changing the play services version to 11.7.0.
You should try using OneSignal Gradle Plugin which helps make the OneSignal Android SDK compatible with your Android Studio project. Use OneSignal-Gradle-Plugin 0.8.0 for OneSignal:[3.7.1, 3.99.99]

Unable to build apk or run the app

The gradle build completes successfully , but while running the application or trying to build the apk I am getting an error:
Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
java.io.IOException: Can't write [F:\TravEz\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\hp.gradle\caches\transforms-1\files-1.1\support-core-ui-27.1.0.aar\51b8cdc0bcfc98652d9ae95f70697b30\jars\classes.jar(;;;;;;**.class)] (Duplicate zip entry [classes.jar:android/support/design/widget/CoordinatorLayout$Behavior.class]))
I have tried all the methods mentioned here
Here is my project level gradle file:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io"}
//Glomadrian maven for animated switch
maven { url "https://dl.bintray.com/glomadrian/maven"}
maven { url "http://dl.bintray.com/lukaville/maven"}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here is my app level gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.travez.travez"
minSdkVersion 19
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
dexOptions {
javaMaxHeapSize "4g"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
compile 'com.github.florent37:materialtextfield:1.0.7'
//library for cardview
implementation 'com.android.support:cardview-v7:26.1.0'
//library for dialog box
implementation 'com.github.d-max:spots-dialog:0.7#aar'
//library for animated switch
implementation 'com.github.glomadrian:MaterialAnimatedSwitch:1.1#aar'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
//Firebase authentication library
implementation 'com.google.firebase:firebase-auth:11.0.4'
//Firebase database library
implementation 'com.google.firebase:firebase-database:11.0.4'
//Google play services and maps libraries
implementation 'com.google.android.gms:play-services-maps:11.0.4'
implementation 'com.google.android.gms:play-services:11.0.4'
implementation 'com.google.android.gms:play-services-location:11.0.4'
//Geofire library
compile 'com.firebase:geofire-android:2.3.0'
//Runtime perission library
compile 'com.github.karanchuri:PermissionManager:0.1.0'
//Material Edit Text library
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
//Calligraphy library
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
// CircleView library
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'id.zelory:compressor:2.1.0'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
compile 'com.android.support:multidex:1.0.0'
compile 'com.nbsp:library:1.8'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
Is written twice, remove one of them.
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
Replace the + with the current version of the library
The problem is because you have duplicated support library in your dependencies.
android-image-cropper is using support library 27+, you can check its build.gradle. MaterialEditText is using support library 22.2.0. Material Animated Switch is using support library 22.2.0. You need to exlude the support libraries from them.
So, instead using the following:
compile 'com.github.florent37:materialtextfield:1.0.7'
implementation 'com.github.glomadrian:MaterialAnimatedSwitch:1.1#aar'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
use the following:
implementation 'com.android.support:support-annotations:26.1.0'
implementation ('com.github.florent37:materialtextfield:1.0.7') {
exclude group: 'com.android.support'
exclude module: 'appcompat-v7'
exclude module: 'support-annotations'
}
implementation ('com.github.glomadrian:MaterialAnimatedSwitch:1.1#aar') {
exclude group: 'com.android.support'
exclude module: 'appcompat-v7'
}
implementation ('com.theartofdev.edmodo:android-image-cropper:2.6.0') {
exclude group: 'com.android.support'
exclude module: 'appcompat-v7'
}
You can check the dependencies tree if you still found the conflicted libraries with:
./gradlew app:dependencies

Firebase Backend in Android [duplicate]

This question already has answers here:
Failed to resolve: com.google.firebase:firebase-core:11.2.0
(6 answers)
Closed 5 years ago.
This is my project's gradle files, I'm trying to get it to sync. I have included error logs, and code . Below you will find the files in order.
I got most of my code from the firebase docs, and still keep getting a fail, when I try syncing my project
Error:(40, 13) Failed to resolve: com.google.firebase:firebase-auth:11.2.0
Show in File<br>Show in Project Structure dialog
Error:(39, 13) Failed to resolve: com.google.firebase:firebase-storage:11.2.0
Show in File<br>Show in Project Structure dialog
Error:Failed to resolve: com.google.firebase:firebase-core:11.2.0
Open File<br>Show in Project Structure dialog
Error:(42, 13) Failed to resolve: com.google.firebase:firebase-database:11.2.0
Show in File<br>Show in Project Structure dialog
Error:Failed to resolve: annotationProcessor
Open File
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
dependencies {
classpath 'com.google.gms:google-services:3.1.0'
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
classpath 'com.google.gms:google-services:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.karanvir.chat"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
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.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
compile('io.socket:socket.io-client:1.0.0') {
// excluding org.json which is provided by Android
exclude group: 'org.json', module: 'json'
}
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.google.firebase:firebase-storage:11.2.0'
compile 'com.google.firebase:firebase-auth:11.2.0'
compile 'com.google.firebase:firebase-messaging:11.2.0'
compile 'com.google.firebase:firebase-database:11.2.0'
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'com.google.gms.google-services'
I think that you have to add the libraries of Firebase to your project, fo example if you need to use the storage you need to add the:
compile 'com.google.firebase:firebase-storage:10.2.1'
in your gradle dependencies, but before of that you need to registrer your project in the Firebase page, get your key and downlowad the
google-services.json
for your project.
Check the tutorials in their page.
https://firebase.google.com/docs/android/setup?hl=es-419
In your application build.grade, try removing:
compile 'com.google.firebase:firebase-storage:11.2.0'
compile 'com.google.firebase:firebase-auth:11.2.0'
compile 'com.google.firebase:firebase-messaging:11.2.0'
compile 'com.google.firebase:firebase-database:11.2.0'
and replacing them with this dependency:
compile 'com.google.android.gms:play-services-gcm:8.4.0'

Categories

Resources