I'm having trouble getting my realm dependencies right for an Android Java project.
I started a new project to try and isolate the problem.
The project is using Android Gradle Plugin Version 7.1.0 and Gradle version 7.2 and Android studio 2021.1.1
I followed the instructions for installing realm in the project. And it builds and runs when I just call
Realm.init(context);
When I try to initialize a synced realm however (buy following the getting Sync quick start guide) I can't seem to get the right imports for the App and AppConfiguration classes.
The build fails with
error: cannot find symbol
App app = new App(new AppConfiguration.Builder("XXXYYYZZZ")
In my older project I see the imports were
import io.realm.mongodb.App;
import io.realm.mongodb.AppConfiguration;
But that doesn't seem to be found by Android studio.
(The RealmTransformer part of the import io.realm.transformer.RealmTransformer line is in read, which is probably not a great sign, but I can't see any warnings in the IDE about it, and it seems to build fine)
Application level gradle file as below
I've tried various combinations of api vs implementation and kapt vs annotationProcessor. Also did "invalidate caches and restart". But nothing worked.
buildscript {
ext.kotlin_version = '1.5.21'
ext.realm_version = '10.10.0'
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath "io.realm:realm-transformer:$realm_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
id 'com.android.application'
}
//apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
import io.realm.transformer.RealmTransformer
android.registerTransform(new RealmTransformer(project))
android {
compileSdk 31
defaultConfig {
applicationId "guru.diederik.myapplication"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
api "io.realm:realm-annotations:$realm_version"
api "io.realm:realm-android-library:$realm_version"
api "io.realm:realm-android-kotlin-extensions:$realm_version"
kapt "io.realm:realm-annotations-processor:$realm_version"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
It seems that the install instructions have been updated. Applying them have now worked, and the project builds.
Project level gradle file that works.
buildscript {
ext.realm_version = '10.10.1'
dependencies {
classpath "io.realm:realm-gradle-plugin:$realm_version"
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And app level gradle file that works
buildscript {
ext.kotlin_version = '1.6.10'
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath "io.realm:realm-transformer:$realm_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
id 'com.android.application'
}
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'
android {
compileSdk 31
defaultConfig {
applicationId "guru.diederik.myapplication"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
realm {
syncEnabled = true
}
dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Related
Problem Occurred while adding Classpath dependencies of Firebase
This is my Gradle.project file
plugins {
id "com.android.application" version "7.3.1" apply false
id "com.android.library" version "7.3.1" apply false
id "com.google.gms.google-services" version "4.3.14" apply false
}
dependencies {
// Add the dependency for the Google services Gradle plugin
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.google.gms:google-services:4.3.14'
}
And this my Gradle Module file
plugins {
id 'com.android.application'
}
apply plugin: 'com.google.gms.google-services'
android {
namespace 'com.example.anonymous'
compileSdk 32
defaultConfig {
applicationId "com.example.anonymous"
minSdk 19
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation platform('com.google.firebase:firebase-bom:31.1.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.airbnb.android:lottie:5.2.0'
implementation 'de.hdodenhof:circleimageview:3.1.0'
}
While Syncing the Gradle I got this error
Could not find method classpath() for arguments [com.android.tools.build:gradle:7.3.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Your build.gradle (project) file should look like this:
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.google.gms:google-services:4.3.14'
}
}
plugins {
id "com.android.application" version "7.3.1" apply false
id "com.android.library" version "7.3.1" apply false
id "com.google.gms.google-services" version "4.3.14" apply false
}
task clean(type: Delete) {
delete rootProject.buildDir
}
All buildscript {} blocks must appear before any plugins {} blocks in the script.
I am working on a project where I help a client to add some features to an app that has been created previously about a year back. I made the changes and have been running into problems while trying to build the project and generate bundle, I have checked round stack overflow and haven't found a solution yet. Please have a look
buildscript {
repositories {
google()
jcenter()
mavenCentral()
maven {
url "https://maven.google.com/"
}
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.3"
classpath 'com.android.tools.lint:lint:30.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:4.3.14'
classpath 'com.android.support:appcompat-v7:28.0.0'
classpath 'com.android.support:support-v4:28.0.0'
}
}
//plugins {
// id 'com.android.application' version '7.2.0' apply false
// id 'com.android.library' version '7.2.0' apply false
//}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://maven.google.com/"}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Here is the app gradle
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
android {
compileSdkVersion 32
defaultConfig {
applicationId "kubet.rhdev.maze"
minSdkVersion 23
targetSdkVersion 32
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'com.google.android.material:material:1.6.1'
implementation 'com.google.android.ads:mediation-test-suite:2.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// implementation 'com.android.support.constraint:constraint-layout:2.0.4'
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.android.support:multidex:2.0.1'
implementation 'com.google.android.gms:play-services-ads:19.6.0'
implementation platform('com.google.firebase:firebase-bom:30.1.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-database:20.0.6'
}
the debug log says
Unable to load class 'com.android.tools.lint.model.LintModelModuleLoaderProvider'.
This is an unexpected error. Please file a bug containing the idea.log file.
Does anyone know how to use Room in an Android Library without having to include any reference to Room in the Android (Java) app?
It's probably useful to note that I'm including a built .aar file of the Android Library in the libs folder which is then referenced by the Android App application level build.gradle. The Android Library and Android App have no connection to each other, other than through the compiled .aar file.
Here's what I'm basically doing:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyCustomLibrary.storeSomething("The thing to store"); //method that calls Room stuff
}
The storeSomething method works as expected if I include Room in the app itself, and throws the following if I exclude it:
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/arch/persistence/room/RoomDatabase;
My goal is to not have the app know anything about Room.
See below for all the build.gradle files.
Android Library project level build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
flatDir {
dirs 'libs'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Android Library plugin level build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 25
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
buildToolsVersion = '28.0.3'
}
dependencies {
def room_version = "1.1.1"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.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 "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
}
Android App project level build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
flatDir {
dirs 'libs'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Android App application level build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.app"
minSdkVersion 25
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
buildToolsVersion = '28.0.3'
}
dependencies {
//def room_version = "1.1.1" (it works if I include this line!)
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.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 "android.arch.persistence.room:runtime:$room_version" (it works if I include this line!)
//annotationProcessor "android.arch.persistence.room:compiler:$room_version" (it works if I include this line!)
}
I've tried to add some modules, and when i rebuild the project i got this error:
error: annotations are not supported in -source 1.3
(use -source 5 or higher to enable annotations)
i'v deleted the modules, but the error is staying.
tried clean and rebuild, didn't help.
i understood it something to do with the java maven, but i didn't understand how to solve it.
Maybe someone here could help?
this is my Gradle:
buildscript {
ext.kotlin_version = '1.3.31'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url "https://maven.java.net/content/groups/public/"
}
maven { url 'https://jitpack.io' }
maven { url "https://maven.google.com" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.eldareini.kotlin.meet4match"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
pickFirst 'META-INF/LICENSE.txt' // picks the JavaMail license file
}
compileOptions {
sourceCompatibility = kotlin_version
targetCompatibility = kotlin_version
}
buildToolsVersion = '28.0.3'
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.sun.mail:android-mail:1.6.0'
implementation 'com.sun.mail:android-activation:1.6.0'
implementation 'com.github.mac229.FragmentUtils:fragmentutils-kt:1.0.1'
implementation 'com.github.mac229.FragmentUtils:fragmentutils:1.0.1'
implementation 'com.sun.mail:android-mail:1.6.0'
implementation 'com.sun.mail:android-activation:1.6.0'
implementation 'org.webrtc:google-webrtc:1.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'
}
You are using the Kotlin version of the library to specify the source/target compatibility of your build.
The problem is here:
compileOptions {
sourceCompatibility = kotlin_version
targetCompatibility = kotlin_version
}
kotlin_version is 1.3
Try the following:
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
My Android is work fine in Android Studio 3.0.1 , but it show the follow build error after I update to the Android Studio 3.1.
Could not find android-maven-gradle-plugin.jar (com.github.dcendents:android-maven-gradle-plugin:2.0).
Searched in the following locations:
https://jcenter.bintray.com/com/github/dcendents/android-maven-gradle-plugin/2.0/android-maven-gradle-plugin-2.0.jar
The build.gradle is like the following:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
jcenter()
maven {
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And in app/build.gradle :
apply plugin: 'com.android.application'
apply plugin: 'android-maven'
apply plugin: 'com.github.dcendents.android-maven'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.aitrix.wen.seaglider"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
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'
testImplementation 'junit:junit:4.12'
compile project(':AHRSView')
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
Did I missing something ? Thanks in advance.
After I update the following , the project work fine.
Update
classpath 'com.android.tools.build:gradle:3.0.1'
to
classpath 'com.android.tools.build:gradle:3.1.0'
And Update
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
to
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
also update the gradle-wrapper.properties to
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip