[英]Realm.init() cannot resolve method init not working in Application onCreate?
Can't call init() method on Realm. 无法在Realm上调用init()方法。 Any ideas what I'm doing wrong?
有什么想法我做错了吗?
I have added the dependency in my build.gradle(project): 我在build.gradle(project)中添加了依赖项:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath "io.realm:realm-gradle-plugin:3.2.0"
}
}
and applied the plugin in the build.gradle(app) 并在build.gradle(app)中应用了插件
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
So I made it work with Realm.init(MyApp.this)
. 因此,我将其与
Realm.init(MyApp.this)
。 I think the issue is you have the dependencies inside the build.gradle of the whole project. 我认为问题在于您在整个项目的build.gradle中具有依赖项。 This:
这个:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.google.gms:google-services:3.0.0'
}
}
allprojects {
repositories {
mavenCentral()
}
}
When you should have it inside the build.gradle of your app: Like this: 当您应该将其包含在应用程序的build.gradle中时:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url 'http://dl.bintray.com/amulyakhare/maven' }
maven { url 'https://jcenter.bintray.com/' }
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
classpath "io.realm:realm-gradle-plugin:3.2.0"
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'realm-android'
repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url 'http://dl.bintray.com/amulyakhare/maven' }
maven { url 'https://jcenter.bintray.com/' }
maven { url "https://jitpack.io" }
}
android {
compileSdkVersion 23
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "nl.hgrams.passenger"
minSdkVersion 17
targetSdkVersion 23
versionCode 900
versionName '2.8.2'
multiDexEnabled true
}
...
}
It seems like a lagg at Android Studio indexes system. Android Studio索引系统似乎滞后 。 Try next solutions:
尝试下一个解决方案:
And the last assumption - move io.realm:realm-gradle-plugin:3.2.0
dependency from project build.gradle file to build.gradle from app and define own buildscript
section: 最后一个假设-将
io.realm:realm-gradle-plugin:3.2.0
依赖项从项目build.gradle文件移至app.build.gradle并定义自己的buildscript
部分:
buildscript { repositories { jcenter() } dependencies { classpath 'io.realm:realm-gradle-plugin:3.2.0' } }
Autogenerated build.gradle for project contains next note about this: 项目的自动生成的build.gradle包含有关此的下一条注释:
// NOTE: Do not place your application dependencies here;
//注意:请勿在此处放置应用程序依赖项; they belong
他们属于
// in the individual module build.gradle files//在各个模块的build.gradle文件中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.