in some cases,we develop in offline, so i download realm jar ,put it into project.
error:
Error:(3, 0) Cause: com/neenbedankt/gradle/androidapt/AndroidAptPlugin
Realm is distributed as an AAR since 0.88.0.
So just adding realm.jar won't work.
I think Gradle's offline mode should be able to handle this by default?
I add android-apt-1.3.jar realm-gradle-plugin-2.1.0.jar realm-transformer-2.1.0.jar into a folder plugin
in build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
// classpath "io.realm:realm-gradle-plugin:1.1.0"
classpath fileTree(dir:'app/plugin',include: ['*.jar'])
}
}
gradle sync an error:
Error:(3, 0) Failed to apply plugin [id 'realm-android']
But as I asked, doesn't Gradle already handle this if you enable Offline Mode?
I have created a small project in Android Studio, added Realm Java 2.0.2 to the two relevant Gradle files (as outlined in the documentation), and sync the project. After that, I set Gradle offline, and I can build.
@ledboot
If Gradle offline mode is not enough, you can create a local maven repository to fetch the files from. This project here shows how it can be accomplished: http://ge.tt/2axpkVf2
i got it,thanks all~ 👍 :)
I was trying to use Realm in offline mode. so,, After gradle succeed, I got following files
realm-annotations-2.0.2.jar
realm-annotations-processor-2.0.2.jar
realm-gradle-plugin-2.0.2.jar
realm-transformer-2.0.2.jar
realm-android-library-2.0.2.aar
in C:\Users\user_name.gradle\caches\modules-2\files-2.1\io.realm
and I moved 3 files (realm-gradle-plugin-2.0.2.jar, realm-transformer-2.0.2.jar, realm-android-library-2.0.2.aar) into libs folder of project and tried to build.
dependencies {
... .... ...
compile fileTree(dir: 'libs', include: ['*.jar'])
compile(name:'realm-android-library-2.0.2', ext:'aar')
}
build is successfull , but app crashes when it running on MyApplication
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Add your initialization code here
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId("E3bTMbxLnMAzuxER2XBSAZWTwcrGe7st95hrxiz1")
.clientKey("s6lhRSbT5jTXK6thLuK28bdTQAxUEispX50BhUS4")
.server("https://parseapi.back4app.com/").build()
);
Realm.init(this);
RealmConfiguration config = new RealmConfiguration.Builder().build();
Realm.setDefaultConfiguration(config);
}
}
Here is log for crash
--------- beginning of crash
11-03 20:11:19.101 21013-21013/com.tahaclay.gifselfiecam E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tahaclay.gifselfiecam, PID: 21013
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/getkeepsafe/relinker/ReLinker;
at io.realm.internal.RealmCore.loadLibrary(RealmCore.java:59)
at io.realm.Realm.init(Realm.java:188)
at com.tahaclay.gifselfiecam.MyApplication.onCreate(MyApplication.java:30)
at com.android.tools.fd.runtime.BootstrapApplication.onCreate(BootstrapApplication.java:369)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5361)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
11-03 20:11:19.101 21013-21013/com.tahaclay.gifselfiecam E/AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.getkeepsafe.relinker.ReLinker" on path: DexPathList[[dex file "/data/data/com.tahaclay.gifselfiecam/files/instant-run/dex/slice-support-annotations-25.0.0_fe0f2ce472817c00cee651dc7aa866e51fea3fd3-classes.dex", dex file "/data/data/com.tahaclay.gifselfiecam/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.tahaclay.gifselfiecam/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.tahaclay.gifselfiecam/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.tahaclay.gifselfiecam/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.tahaclay.gifselfiecam/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.tahaclay.gifselfiecam/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.tahaclay.gifselfiecam/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.tahaclay.gifselfiecam/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.tahaclay.gifselfiecam/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.tahaclay.gifselfiecam/files/instant-run/dex/slice-slice_0-classes.dex", dex file "
Realm depends on the ReLinker library so you need to download that too.
@cmelchior The link http://ge.tt/2axpkVf2 is blocked by chrome and any download is automatically flagged as malicious from the site. Firefox doesn't even trigger a download. Can you post the project to another file share? Thanks.
@kneth , I added ReLinker library as you told, but another crash issue.
dependencies {
......
compile(name: 'relinker-1.2.2', ext: 'aar')
compile(name:'realm-android-library-2.0.2', ext:'aar')
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mContainer = container;
View view = inflater.inflate(R.layout.fragment_animate, container, false);
listView = (ListView) view.findViewById(R.id.fragment_animate_list);
results = realm.where(GSCAnimation.class).findAll(); >>>>> **crashes on here**
loadingView = (LoadingView) view.findViewById(R.id.electric_fan_view);
adapter = new AnimateListAdapter(getActivity(), results);
listView.setAdapter(adapter);
});
return view;
}
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tahaclay.gifselfiecam, PID: 3395
java.lang.IllegalArgumentException: GSCAnimation is not part of the schema for this Realm
at io.realm.internal.modules.CompositeMediator.getMediator(CompositeMediator.java:172)
at io.realm.internal.modules.CompositeMediator.getTableName(CompositeMediator.java:90)
at io.realm.RealmSchema.getTable(RealmSchema.java:296)
at io.realm.RealmSchema.getSchemaForClass(RealmSchema.java:316)
at io.realm.RealmQuery.
at io.realm.RealmQuery.createQuery(RealmQuery.java:87)
at io.realm.Realm.where(Realm.java:1214)
at com.tahaclay.gifselfiecam.fragments.GSCAnimateFragment.onCreateView(GSCAnimateFragment.java:73)
at android.app.Fragment.performCreateView(Fragment.java:2353)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:995)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1171)
at android.app.BackStackRecord.run(BackStackRecord.java:815)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1578)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:483)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
It looks like the annotation processor hasn't been executed. You might have to add @RealmClass to your model classes.
Most helpful comment
@ledboot
If Gradle offline mode is not enough, you can create a local maven repository to fetch the files from. This project here shows how it can be accomplished: http://ge.tt/2axpkVf2