Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] Make examples compile with AGP 8 #7811

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dependencies.list
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ REALM_BAAS_GIT_HASH=7ba774ab4740e892f701870b4afc6a2c9c682202
REALM_BAAS_UI_GIT_HASH=50bd2bb1d78a8a6ab04202aaa2f50350882b0fe2

# Common Android settings across projects
GRADLE_BUILD_TOOLS=7.4.0
GRADLE_BUILD_TOOLS=8.0.0
ANDROID_BUILD_TOOLS=30.0.3
KOTLIN=1.6.21
KOTLIN_COROUTINES=1.6.0

# Common classpath dependencies
gradle=7.5
gradle=8.0
ndkVersion=23.1.7779620
BUILD_INFO_EXTRACTOR_GRADLE=4.17.0
GRADLE_NEXUS_PLUGIN=1.0.0
Expand Down
1 change: 1 addition & 0 deletions examples/architectureComponentsExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
namespace 'io.realm.examples.arch'
compileSdkVersion rootProject.sdkVersion
buildToolsVersion rootProject.buildTools

Expand Down
1 change: 1 addition & 0 deletions examples/compatibilityExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ apply plugin: 'kotlin-android-extensions'
apply plugin: 'realm-android'

android {
namespace 'io.realm.examples.compatibility'
compileSdkVersion rootProject.sdkVersion
buildToolsVersion rootProject.buildTools

Expand Down
1 change: 1 addition & 0 deletions examples/coroutinesExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'

android {
namespace "io.realm.examples.coroutinesexample"
// androidx.lifecycle dependencies requires Android APIs 31 or later
compileSdkVersion 31
buildToolsVersion rootProject.buildTools
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MainActivity : AppCompatActivity(), MainFragment.OnItemClicked {
val detailsFragment = DetailsFragment.instantiate(DetailsFragment.ArgsBundle(id))

supportFragmentManager.commit {
setCustomAnimations(R.anim.fragment_open_enter, R.anim.fragment_open_exit)
// setCustomAnimations(R.anim.fragment_open_enter, R.anim.fragment_open_exit)
add(R.id.container, detailsFragment, DetailsFragment.TAG)
hide(requireNotNull(mainFragment))
addToBackStack(null)
Expand Down
1 change: 1 addition & 0 deletions examples/encryptionExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
namespace 'io.realm.examples.encryption'
compileSdkVersion rootProject.sdkVersion
buildToolsVersion rootProject.buildTools

Expand Down
2 changes: 1 addition & 1 deletion examples/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
org.gradle.jvmargs=-Xmx2048M -XX:MaxMetaspaceSize=1024M
org.gradle.caching=true
android.enableD8=true

# Gradle sync failed: Due to a limitation of Gradle’s new variant-aware dependency management, loading the Android Gradle plugin in different class loaders leads to a build error.
# This can occur when the buildscript classpaths that contain the Android Gradle plugin in sub-projects, or included projects in the case of composite builds, are set differently.
Expand All @@ -13,3 +12,4 @@ android.enableBuildScriptClasspathCheck=false
# See https://developer.android.com/studio/build/optimize-your-build#configuration_on_demand
org.gradle.configureondemand=false
android.useAndroidX=true
android.defaults.buildfeatures.buildconfig=true
2 changes: 1 addition & 1 deletion examples/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
1 change: 1 addition & 0 deletions examples/gridViewExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
namespace 'io.realm.examples.realmgridview'
compileSdkVersion rootProject.sdkVersion
buildToolsVersion rootProject.buildTools

Expand Down
1 change: 1 addition & 0 deletions examples/introExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
namespace 'io.realm.examples.intro'
compileSdkVersion rootProject.sdkVersion
buildToolsVersion rootProject.buildTools

Expand Down
1 change: 1 addition & 0 deletions examples/jsonExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
namespace 'io.realm.examples.json'
compileSdkVersion rootProject.sdkVersion
buildToolsVersion rootProject.buildTools

Expand Down
1 change: 1 addition & 0 deletions examples/kotlinExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ apply plugin: 'kotlin-kapt'
apply plugin: 'realm-android'

android {
namespace 'io.realm.examples.kotlin'
//noinspection GroovyAssignabilityCheck
compileSdkVersion rootProject.sdkVersion
//noinspection GroovyAssignabilityCheck
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ open class Person(
// If you use non-nullable types, properties must be initialized with non-null values.
@PrimaryKey var id: Long = 0,

var name: String = "",
var name: String? = "",

var age: Int = 0,

Expand Down
1 change: 1 addition & 0 deletions examples/migrationExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
namespace "examples.realm.io.migration"
compileSdkVersion rootProject.sdkVersion
buildToolsVersion rootProject.buildTools

Expand Down
2 changes: 1 addition & 1 deletion examples/migrationExample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.realm.examples.realmmigrationexample" >
package="examples.realm.io.migration" >

<application
android:name=".MyApplication"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.IOException;
import java.io.InputStream;

import examples.realm.io.migration.R;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import io.realm.examples.realmmigrationexample.model.Migration;
Expand All @@ -49,7 +50,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_realm_migration_example);

rootLayout = ((LinearLayout) findViewById(R.id.container));
rootLayout = ((LinearLayout) findViewById(examples.realm.io.migration.R.id.container));
rootLayout.removeAllViews();

// 3 versions of the databases for testing. Normally you would only have one.
Expand Down
1 change: 1 addition & 0 deletions examples/moduleExample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
namespace 'io.realm.examples.appmodules'
compileSdkVersion rootProject.sdkVersion
buildToolsVersion rootProject.buildTools

Expand Down
1 change: 1 addition & 0 deletions examples/moduleExample/library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'realm-android'

android {
namespace 'io.realm.examples.librarymodules'
compileSdkVersion rootProject.sdkVersion
buildToolsVersion rootProject.buildTools

Expand Down
1 change: 1 addition & 0 deletions examples/mongoDbRealmExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ apply plugin: 'kotlin-android-extensions'
apply plugin: 'realm-android'

android {
namespace 'com.mongodb.realm.example'
// androidx.lifecycle dependencies requires Android APIs 31 or later
compileSdkVersion 31
buildToolsVersion rootProject.buildTools
Expand Down
1 change: 1 addition & 0 deletions examples/multiprocessExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
namespace "io.realm.examples.realmmultiprocessexample"
compileSdkVersion rootProject.sdkVersion
buildToolsVersion rootProject.buildTools

Expand Down
1 change: 1 addition & 0 deletions examples/rxJavaExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
namespace 'io.realm.examples.rxjava'
//noinspection GroovyAssignabilityCheck
compileSdkVersion rootProject.sdkVersion
//noinspection GroovyAssignabilityCheck
Expand Down
1 change: 1 addition & 0 deletions examples/threadExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
namespace "io.realm.examples.threads"
compileSdkVersion rootProject.sdkVersion
buildToolsVersion rootProject.buildTools

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import io.realm.RealmResults;
import io.realm.Sort;
import io.realm.examples.threads.model.Dot;
import io.realm.examples.threads.R;

/**
* This fragment demonstrates how you can perform asynchronous queries with Realm.
Expand Down Expand Up @@ -86,45 +87,41 @@ public void onStop() {

@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.translate_button: {
cancelAsyncTransaction();
// translate all points coordinates using an async transaction
asyncTransaction = realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
// query for all points
RealmResults<Dot> dots = realm.where(Dot.class).findAll();

for (int i = dots.size() - 1; i >= 0; i--) {
Dot dot = dots.get(i);
if (dot.isValid()) {
int x = dot.getX();
int y = dot.getY();
dot.setX(y);
dot.setY(x);
}
if (view.getId() == R.id.translate_button) {
cancelAsyncTransaction();
// translate all points coordinates using an async transaction
asyncTransaction = realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
// query for all points
RealmResults<Dot> dots = realm.where(Dot.class).findAll();

for (int i = dots.size() - 1; i >= 0; i--) {
Dot dot = dots.get(i);
if (dot.isValid()) {
int x = dot.getX();
int y = dot.getY();
dot.setX(y);
dot.setY(x);
}
}
}, new Realm.Transaction.OnSuccess() {
@Override
public void onSuccess() {
if (isAdded()) {
Toast.makeText(getActivity(), "Translation completed", Toast.LENGTH_SHORT).show();
}
}
}, new Realm.Transaction.OnSuccess() {
@Override
public void onSuccess() {
if (isAdded()) {
Toast.makeText(getActivity(), "Translation completed", Toast.LENGTH_SHORT).show();
}
}, new Realm.Transaction.OnError() {

@Override
public void onError(Throwable e) {
if (isAdded()) {
Toast.makeText(getActivity(), "Error while translating dots", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
}, new Realm.Transaction.OnError() {
@Override
public void onError(Throwable e) {
if (isAdded()) {
Toast.makeText(getActivity(), "Error while translating dots", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
});
break;
}
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import io.realm.RealmChangeListener;
import io.realm.examples.threads.model.Dot;
import io.realm.examples.threads.widget.DotsView;
import io.realm.examples.threads.R;

/**
* This fragment demonstrates how Realm can interact with a background thread.
Expand All @@ -43,6 +44,9 @@ public class ThreadFragment extends Fragment {
private Thread backgroundThread;
private DotsView dotsView;

private final int actionAdd = R.id.action_add_dot;
private final int actionClear = R.id.action_clear;

// Realm change listener that refreshes the UI when there is changes to Realm.
private RealmChangeListener<Realm> realmListener = new RealmChangeListener<Realm>() {
@Override
Expand Down Expand Up @@ -72,32 +76,28 @@ public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

@Override
public boolean onOptionsItemSelected(MenuItem item) {

switch(item.getItemId()) {
case R.id.action_add_dot:
// Add blue dot from the UI thread
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
Dot dot = realm.createObject(Dot.class);
dot.setX(random.nextInt(100));
dot.setY(random.nextInt(100));
dot.setColor(getResources().getColor(R.color.realm_blue));
}
});
return true;

case R.id.action_clear:
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
realm.delete(Dot.class);
}
});
return true;

default:
return super.onOptionsItemSelected(item);
if (item.getItemId() == R.id.action_add_dot) {
// Add blue dot from the UI thread
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
Dot dot = realm.createObject(Dot.class);
dot.setX(random.nextInt(100));
dot.setY(random.nextInt(100));
dot.setColor(getResources().getColor(R.color.realm_blue));
}
});
return true;
} else if (item.getItemId() == R.id.action_clear) {
realm.executeTransaction(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
realm.delete(Dot.class);
}
});
return true;
} else {
return super.onOptionsItemSelected(item);
}
}

Expand Down
1 change: 1 addition & 0 deletions examples/unitTestExample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
namespace 'io.realm.examples.unittesting'
compileSdkVersion rootProject.sdkVersion
buildToolsVersion rootProject.buildTools

Expand Down