How to implement Realm database in android library? - android

Install Realm as a Gradle plugin.
Step 1: Add the class path dependency to the project level build.gradle file.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:5.3.1"
}
}
Step 2: Apply the realm-android plugin to the top of the application level build.gradle file.
apply plugin: 'realm-android'
Step 3 : add dependencies
implementation 'io.realm:android-adapters:2.0.0'
But when I build my project this error find :
Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
Full build.gradle(Module) file.
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.myfirastapp"
minSdkVersion 21
targetSdkVersion 28
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:28.0.0-alpha3'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
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 'com.android.support:design:28.0.0-alpha3'
implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'io.realm:android-adapters:2.0.0'
}
and build.gradle(Project)
// 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.1.3'
classpath "io.realm:realm-gradle-plugin:3.1.4"
// 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
}

replace all 'compile' with 'implementation' in gradle file

Related

An error occurs configuring project:app in developing android app using gradle build tools

I am new to android development and I 'm building android app. I'm using gradle and I got the error message A problem occurred configuring project ':app'.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
//classpath 'ext.supportLibraryVersion = 27.1.1'
classpath 'com.android.support:support-v4:27.1.1'
classpath 'com.google.gms:google-services:4.3.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
}
The above code is the project level of build.gradle file.
The following code is the app level of build.gradle file.
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "mm.com.fairway.firebaseauth"
minSdkVersion 22
targetSdkVersion 27
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:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-analytics:17.2.0'
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'
I searched the solution to fix this error and I don't find the solution yet. Any ideas for this error and Thank you.
classpath 'com.android.support:support-v4:27.1.1
The above line is in the wrong Gradle file. Also change it from classpath to implementation.
So something like this:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
//classpath 'ext.supportLibraryVersion = 27.1.1'
classpath 'com.google.gms:google-services:4.3.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
}
and
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "mm.com.fairway.firebaseauth"
minSdkVersion 22
targetSdkVersion 28
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:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.google.firebase:firebase-analytics:17.2.1'
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'
}
apply plugin: 'com.google.gms.google-services'
Do note, I updated the project to 28 and other dependencies were also upgraded. I did this as I don't have SDK 27 installed anymore.
Upgrading your Gradle build tools to 3.2 or higher will solve this problem.
For example:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
//classpath 'ext.supportLibraryVersion = 27.1.1'
classpath 'com.android.support:support-v4:27.1.1'
classpath 'com.google.gms:google-services:4.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
This solved it for me and seems to have solved it for this other person as well:
I have a gradle sync error JAVA_LETTER_OR_DIGIT when trying to add Firebase to my android project

Kotlin Android Apollo client is not generating Schema classes

I am developing an Android application. In my application, I am using Apollo client to consume GraphQL API. When I build the project, it is not generating the classes based on the schema.json file. This is what I have done so far.
This is my app grandle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.apollographql.android'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.memento"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.apollographql.apollo:apollo-runtime:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
compileOnly 'org.jetbrains:annotations:13.0'
testCompileOnly 'org.jetbrains:annotations:13.0'
}
This is my project grandle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.41'
repositories {
google()
jcenter()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.apollographql.apollo:apollo-gradle-plugin:1.1.3'
classpath 'com.apollographql.apollo:apollo-gradle-plugin:1.2.0-SNAPSHOT'
// 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
}
I have the schema.json and this is the project structure
When I build the project, the classes are generated in this folder
But I cannot call those classes in my code. It is showing this error.
How can I use those classes in my code?
You need to make query in a file with .graphql extension on same location as your Schema.json is. Then rebuild your project and it will generate classes.

(android studio 3.2 Beta 2) - 'android.support.v4.media' error. How to resolve it.

I am using android studio 3.2 Beta 2 for the application development. I am facing the error for support version 4 media in media browser compact custom action callback. My Error look like below:
"Error: Program type already present: android.support.v4.media.MediaBrowserCompat$CustomActionCallback"
My gradle for app level look like this.
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.sa.restaurant"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-alpha1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha3'
implementation 'com.google.android.material:material:1.0.0-alpha1'
implementation "androidx.room:room-runtime:2.0.0-alpha1"
annotationProcessor "androidx.room:room-compiler:2.0.0-alpha1"
kapt "androidx.room:room-compiler:2.0.0-alpha1"
implementation 'com.google.android.gms:play-services-places:15.0.1'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
}
And gradle file for Project Level look like this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.51'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-beta02'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// 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.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Kotlin Unresolved Reference When Using Library

I am writing an Android app in Kotlin. I am using this library.
Following the instructions present at the bottom of the readme, I added the following line:
implementation 'net.dean.kdown:kdown:0.4.0'
in my "Module: app" build.gradle script.
I also have the line jcenter() in my "Project" build.gradle script
I then added the import net.dean.kdown.* in my imports in my "MainActivity.kt" file.
As a test, I tried using the library in my onCreate method, as follows:
val downloader = Kdown();
But, I'm getting the error "Unresolved reference: Kdown". Also, the IDE is giving the "Unused Import Directive" error, even though, theoretically, I should be using the import to create the "downloader" object.
Why isn't this working?
Here's my build.gradle file for the project.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.30'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// 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
}
Here's my app module's build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.rstudios.vroy1.animefacekeyboard"
minSdkVersion 15
targetSdkVersion 27
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"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.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'
implementation 'net.dean.kdown:kdown:0.4.0'
}

Error:(33, 0) Could not find method classpath() for arguments [com.google.gms:google-services:3.0.1]

Trying to configure Firebase for my android project. But I get sync error.
build.gradle app directory:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.yunus.relichunter"
minSdkVersion 15
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 {
compile 'com.google.firebase:firebase-core:11.8.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.google.firebase:firebase-auth:11.8.0'
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'
classpath 'com.google.gms:google-services:3.0.1'
}
apply plugin: 'com.google.gms.google-services'
build.gradle root directory :
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven {
url "https://maven.google.com" // Google's Maven repository
}
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
You can see the error on the image shown above.
I have tried to install Firebase using its assistance (tools/Firebase) then I tried to do it normally.
As #tyczj says, you can't use classpath 'com.google.gms:google-services:3.0.1' in your module build.gradle (like app module) dependencies block. You only can use it in your project or root build.gradle dependencies block.

Categories

Resources