Cannot import realm classes in Android Studio - java

I'm using android studio 2.1.3, gradle version 2.1.3 , realm 2.2.1 and java 8
I can import classes like
io.realm.Realm;
io.realm.RealmQuery;
io.realm.RealmResults;
and project compiles successfully
but I cannot import classes like
io.realm.SyncCredentials;
io.realm.ObjectServerError;
io.realm.SyncUser;
basically object server related classes.
for some reason studio cannot find those classes. I've included correct code in both the build.gradle files.
any suggestions ?

In order to enable sync classes, you need to enable sync in the Realm plugin.
Enabling Realm Mobile Platform
In order to to enable Realm Mobile Platform you must add the following section to your app’s build.gradle:
realm {
syncEnabled = true;
}

Read this - you need add Realm plugin: https://realm.io/docs/java/latest/#getting-started

Related

How to import & use github repos in Android Studio

I've spent hours trying to import/use a custom github repo for an android app and am having no luck. I'm new to Android Studio but can't seem to import the repo such that I can use its methods. I've tried a lot of recommendations from here and the wider web without success. Probably because the posts I have come across are 5+ years old...
Have tried adding the following to to build.gradle (:app), but I get an error "Failed to resolve: com.github.pkleczko:CustomGauge:1.0.4":
implementation 'com.github.pkleczko:CustomGauge:1.0.4'
Have tried adding the the following to the above, but this gives me the error "Build was configured to prefer settings repositories over project repositories but repository 'MavenRepo' was added by build file 'app\build.gradle'":
repositories {
mavenCentral()
}
Have tried using New -> Import Module and New -> Project from Version Control per this, but these just opened the repo in a new window.
Having CustomGuage as a dependency for my app module didn't seem to do anything either.
It shouldn't be this hard, should it?! Please help, what am I doing wrong?! Do I need to import the project and then refactor it for my needs rather than using it as a 'library'? Do I need to add an import statement to my java file?
Thank you!
This is an old project. You can see his warehouse introduction. He uploaded it in jcenter. Of course, mavenCentral will not.
this is repository -> pkleczko/CustomGauge

how to add/get a new plugin service like inAppBillingService, in an existing java eclipse project with gluon

At the beginning of the project, I had already installed some services like magnetometer and accelerometer.
Now, I want to connect my application to the Google Play by using the InAppBilling service. But I don't know to connect this new plugin with my eclipse project. I have checked that, by adding, in build.gradle file, the plugin 'vibration' in its jfxmobile - downconfig section. Gradle fetches the new service 'vibration'. And I use the same way for adding 'inAppBilling'
Perhaps, concerning the inAppBilling plugin, is it a problem of versions ?
I use
jfxmobile-plugin:1.3.8
com.gluonhq:charm:4.3.0
javafxportsVersion = '8.60.9'
downConfig {version '3.5.0'
After an additional analysis, I have solved te problem: it was a problem of name. Write 'in-app-billing' instead of 'inappbilling' in the build.gradle file, as follows:
jfxmobile {
javafxportsVersion = '8.60.9'
downConfig {
version '3.5.0'
plugins 'accelerometer', 'device', 'storage', 'display', 'in-app-billing'
}
Note that I have also modified the gluonhq.charm version from 4.3.0 to 5.0.0, as follows:
dependencies {
compile 'com.gluonhq:charm:5.0.0'
}
With this new compiler version, the performance of the executable is better or not?
Thanks

Gradle dependency vs. java import statement in Android studio

I'm trying to pull together an Android project, it includes several library packages, and a demo app that utilize the libraries.
I'm using Android Studio and Gradle. (I used to work with Eclipse, without gradle.)
So here in Android Studio, I have a project including several packages(or modules? what's the difference in concept?)
I have a core library project. And another library, say Flavor, that utilizes core.
In the Flavor module,
In build.gradle file, I have
dependencies {
....
compile project(':**core-project**')
....
}
I understand it as that Gradle add the core project build path to my Flavor project. (Same way that you can do it manually in Eclipse. See picture)
In java file,
import org.project.**core**; //this shows Unused
public MyFlavorClass extends CoreClass {
...
}
I deleted the import statement and it seems fine.
So why the import statement is not needed here?

Google Maps v2 in the Android Studio. Not found GeoPoint

I am working on a code that was made in the Eclipse and i am migrating to Android Studio, however i am having a problem to the to import
com.google.android.maps.GeoPoint;
but i can import
com.google.android.gms.maps.GoogleMap;
I've tried to add in my Gradle file
compile 'com.google.android.gms:play-services:6.5.87'
and also i've tried also to use .jar, however i didn't have good results.
compile files('libs/google-play-services.jar')
I searched about this in many places, but i found nothing to help me, case somebody have resolved this problem and want help me i thank you.
To work, i had that to replace the below line in the my Gradle file.
android {
...
compileSdkVersion 16
...
}
To
android {
...
compileSdkVersion "Google Inc.:Google APIs:16"
...
}
Please following all the steps to Add Google Play Services to Your Project in Android Studio:
1.Open the build.gradle file inside your application module directory.
Note: Android Studio projects contain a top-level build.gradle file and a build.gradle file for each module. Be sure to edit the file for your application module. See Building Your Project with Gradle for more information about Gradle.
2.Add a new build rule under dependencies for the latest version of play-services. For example:
apply plugin: 'com.android.application'
...
dependencies {
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
}
Be sure you update this version number each time Google Play services is updated.
Note: If the number of method references in your app exceeds the 65K limit, your app may fail to compile. You may be able to mitigate this problem when compiling your app by specifying only the specific Google Play services APIs your app uses, instead of all of them. For information on how to do this, see Selectively compiling APIs into your executable.
3.Save the changes and click Sync Project with Gradle Files in the toolbar.
4.Open your app's manifest file and add the following tag as a child of the element:
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
You can now begin developing features with the Google Play services APIs.
Please refer to here for more details.

What is com.android.support:appcompat-v7?

I am not familiar with using Android Studio. Earlier I used Eclipse. Could you explain me what is gradle in Android studio. I have problem with Android Studio. What confused me is that it uses the same android sdk as eclipse but when I create a new project weird things happens:
There is required :com.android.support:appcompat-v7:+ (what it is ? eclipse does not require it)
My MainActivity extends ActionBarActivity instead of Activity why is that ?
Its a support library called appcompat. You need to reference that if you need actionbar below api level 11 (Whether its android studio or eclipse).
If you need actionbar below api level 11 your Activity needs to extend ActionBarActivity.
If you are targetting api level 11 and above then you don't need to extend ActionBarActivity and reference AppCompat. You can simply extend Activity and you will have actionabr by default.
Check Adding the Action Bar in the below link.
http://developer.android.com/guide/topics/ui/actionbar.html
Check for Adding libraries with resources using Android Studio #
https://developer.android.com/tools/support-library/setup.html
Actiobbar is introduced in api level 11. com.android.support:appcompat-v7:+ is a support library which allows you to have an ActionBar in your app for devices running on Android 3.0 or below.
Android Studio default project includes it automatically in dependencies and extends ActionbarActivity instead of Activity in order to use it.
You can check the same in your module's build.gradle file, you will find something like this under your dependencies block.
compile 'com.android.support:appcompat-v7:+'
There are two possible solutions to get rid of this
Remove above line from dependencies block and extend Activity instead of ActionBarActivity in your Activity classes.
Download support repository from Android SDK Manager.
Support Repository and Google Repository shown in SDK manager are not required for Eclipse but in order use Google Play Services and Support libraries in Android Stodio you have to download them.
EDIT(android plugin not found error, asked in comments below ) :
Make sure you have this either in your root level build.gradle file or at the top of module's build.gradle file to let build system know where your gradle pguin is and what is the version :
(before apply plugin: 'android')
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}

Categories

Resources