How to install realm as a gradle dependency? - android

I am completely new to realm. I want to use realm db in my android project. I have gone through the official Realm documentation. I need to set up realm in my android project. For that I have added the gradle dependancy as
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:0.88.2"
}
}
apply plugin: 'realm-android'
This is what they have given in documentation. But this doesn't work for me. It gives error saying Plugin with id 'realm-android' not found.
This is my build.gradle file
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.db.realmsample"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:0.88.2"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
}
Is my configuration correct?

Move the buildscript to your main build.gradle file (Project) , it shouldn't be there in build.gradle (module:app)
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:<realm version>"
}
}
This should go to main build.gradle

First of all copy the class path dependency to build.gradle file(Project):-
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:1.2.0"
}
}
Finally, copy and paste the following code on top of build.gradle(App) :-
apply plugin: 'realm-android'
Note:- The version 1.2.0 is subjected to change on future releases.For more please check https://realm.io/docs/java/latest/

Prerequisites
Android Studio version 1.5.1 or higher
JDK version 7.0 or higher
A recent version of the Android SDK
Android API Level 9 or higher (Android 2.3 and above)
Step 1: Add the class path dependency to the project level build.gradle file.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "io.realm:realm-gradle-plugin:4.1.1"
}
}
Step 2: Apply the realm-android plugin to the top of the application level build.gradle file.
apply plugin: 'realm-android'
Step 3: Gradle sync
For the official complete installation guide. Please see the following link.
https://realm.io/docs/java/latest/#installation

The method I used is
` dependencies
{
classpath 'com.android.tools.build:gradle:3.0.0'
classpath "io.realm:realm-gradle-plugin:3.1.4"
}`
in your main build gradle file
then add
apply plugin: 'realm-android'
and
compile 'io.realm:android-adapters:2.0.0'
in your app's build gradle
this link to bintray will give you the latest build
https://bintray.com/realm/maven/realm-android-library/3.4.0#files/io%2Frealm%2Frealm-android-library%2F3.4.0

Related

Android ERROR: Failed to resolve: com.firebase:firebase-jobdispatcher:0.8.5 ? firebase error

I'm trying to use the Pusher Beams API for push notifications. It said I need to integrate Firebase with my project first, but I keep getting the following error and none of the resources I found online have helped (which basically all call to play around with the firebase core versions)
ERROR: Failed to resolve: com.firebase:firebase-jobdispatcher:0.8.5
******* APP LEVEL BUILD.GRADLE **************
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.parse.starter"
// minSdkVersion rootProject.ext.minSdkVersion
minSdkVersion 21
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.parse.bolts:bolts-tasks:1.3.0'
implementation 'com.parse:parse-android:1.13.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-messaging:18.0.0'
implementation 'com.pusher:push-notifications-android:1.4.3'
}
apply plugin: 'com.google.gms.google-services'
*** PROJECT LEVEL BUILD.GRADLE *******
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
google()
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
ext {
compileSdkVersion = 22
buildToolsVersion = "23.0.1"
minSdkVersion = 9
targetSdkVersion = 23
}
PROBLEM: the gradle refuses to sync. I've tried to clean/rebuild project/restart android studio, here's the sync error:
this is the error when trying to sync the gradle:
ERROR: Failed to resolve: com.firebase:firebase-jobdispatcher:0.8.5
Show in Project Structure dialog
Affected Modules: ParseStarterProject
This might be coming from com.pusher:push-notifications-android:1.4.4. see the build.gradle.
com.firebase:firebase-jobdispatcher:0.8.5 had been deprecated (maybe removed from the Maven repository) and replaced with androidx WorkManager.
If you still need it, it's on mavenCentral() repository.
You may need to update your project level build.gradle:
buildscript {
repositories {
google()
jcenter()
}
...
}
allprojects {
repositories {
google()
jcenter()
}
}
According to Firebase Docs
You no longer need to add the Android library com.google.firebase:firebase-core
Try to remove firebase-core dependency and see. For more info, refer to this

Using Hugo Plugin

I'm trying to use the Hugo library developed by Jake Wharton.
I added the statement:
compile 'com.jakewharton.hugo:hugo-plugin:1.2.1'
to my dependencies in my build.gradle file at the app level.
Then when I try to annotate with #DebugLog on my methods, it appears in red, as if the IDE doesn't recognize it.
I tried typing in an import statement like:
import com.jakewharton.hugo;
but the jakewharton part of the import statement appears in red, meaning it doesn't see it.
I've googled, and found references like:
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
I'm not sure what the difference between compile and classpath is.
Also, I see a reference to:
apply plugin: 'hugo'
Where should that go?
As you can see I'm totally lost. Any ideas on how to make this work is greatly appreaciated.
I'm not sure you are referencing the app module build.gradle or the project level build.gradle.
But eventually, I put it all in the app module build.grade and it worked for me. This is how the file looked like:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.hugo'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.app_name"
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
}
A correct configuration would look like this in your build.gradle file:
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.hugo'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
}
}
dependencies {
// Other dependencies
}
There is no need to add Hugo to the second dependencies section, this is done for you by the plugin.
I had had the same problem, but realized I had apply plugin: 'com.android.application' typed twice. Once I deleted the extra reference, placing the Jake Wharton stuff at the top of build.gradle (app), it removed the red lines.

Android studio 1.0.2 - gradle project sync failed

I have started using Android Studio 1.0.2 and I am trying to add Library dependency. For example I am adding loopj library in my project.
Steps which I follow:
File > Project Structure > Module(app) > Dependencies tab > Click on + icon > select loopj library > Apply > OK
Now I am getting issue of Gradle project sync failed.
Message : Failed to find: com.loopj.android:android-async-http:1.4.6
Somebody else facing the same problem? Please provide me suggestion if any.
Other information
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.test.testapplication"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.loopj.android:android-async-http:1.4.6'
}
//
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
//
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-2.2.1-all.zip
I've faced the same problem. The solution was simple, all you need is upgrade your gradle version. To do this, open your build.gradle (root project) and edit the next line:
classpath 'com.android.tools.build:gradle:1.0.0'
to
classpath 'com.android.tools.build:gradle:1.1.0'
So if you are using Android Studio you will notice that you are using offline mode that's not available in the new gradle version. Confirm the change and now you can download the dependencies you want.

Android Studio Error: (8, 0) Plugin with id 'android' not found

I have installed Android Studio (0.6.1) on OS X (10.9.3) and Gradle 1.1 using Brew (brew install gradle). However, I can't get my first Hello World! project... Please help me solve this issue
build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion '19.1'
defaultConfig {}
productFlavors {}
}
dependencies {
}
Error message:
Error:(8, 0) Plugin with id 'android' not found.
Getting Build failed with an Exception Android Studio 0.4.3 and 0.4.4 post and Android Studio: Plugin with id 'android-library' not found post does not solves the problem...
Second post I linked returns this error message:
Error:The project is using an unsupported version of Gradle. Please
use version 1.10. Please point to a supported Gradle version in the
project's Gradle settings or in the project's Gradle wrapper (if
applicable.) Fix Gradle wrapper and
re-import project Gradle settings
It seems you have missed to add android gradle plugin dependency in dependencies block.
Replace the top buildScript section by this and sync your project with gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
applicationId 'YOUR_APP_PACKAGE'
minSdkVersion 9
targetSdkVersion 17
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors { }
}
dependencies {
}
build.gradle file inside my "app" folder: PATH: /home/work/ProjectName/app/build.gradle
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 11
targetSdkVersion 19
versionCode 1
versionName '1.0'
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile 'com.android.support:appcompat-v7:+'
}
}
build.gradle file outside my "app" folder: PATH: /home/work/ProjectName/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Note after all these update synchronise your project with gradle file
Put below code in build.gradle file of main Application and sync it.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
mavenCentral()
}
}
Credit to Ganesh Katikar

Android Studio with Transfuse

I can successfully set up Transfuse in my android project but when it comes to running the app using Android Studio, it fails. Probably because the Manifest xml has to be empty for Transfuse to take care of.
Has anyone ever got these working together?
Transfuse and Android Studio work remarkably well together. The trick is to get Transfuse integrated with Gradle. Once you get Gradle working, the build will just kick off the annotation processor and run Transfuse.
I've put together an example reference project here: https://github.com/johncarl81/transfuse/tree/master/examples/gradle
Here's the procedure to get there:
Have Android Studio generate a new Android project
Move the AndroidManifest.xml file to the root of the Android project, ie:
~/project/src/main/AndroidManifest.xml -> ~/project/AndroidManifest.xml
Setup the new AndroidManifest.xml location in the gradle.build file:
android {
...
sourceSets.main {
manifest.srcFile 'AndroidManifest.xml'
}
}
Add the APT plugin:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.1'
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
apply plugin: 'android-apt'
Finally add transfuse and transfuse-api:
dependencies {
apt 'org.androidtransfuse:transfuse:0.2.7'
compile 'org.androidtransfuse:transfuse-api:0.2.7'
}
Your final gradle.build will look like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.1'
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
apply plugin: 'android-apt'
repositories {
mavenCentral()
}
dependencies {
apt 'org.androidtransfuse:transfuse:0.2.7'
compile 'org.androidtransfuse:transfuse-api:0.2.7'
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
sourceSets.main {
manifest.srcFile 'AndroidManifest.xml'
}
}
Edit:
Finally you probably want to add the source/apt_generated/debug or source/apt_generated/release folders as source folders under the project configuration.
Second Edit:
I updated the above example with the new Android-APT plugin
For anyone struggling with "Could not find the AndroidManifest.xml" with Transfuse 3 beta 5, I fixed by adding this to my gradle file:
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
}
}

Categories

Resources