From 002b77a634430565ebbadc30e7cf4d0d23d57103 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 15 Mar 2018 02:02:25 +0100 Subject: [PATCH 01/47] Prepare for next major version --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index c30f0ec2be..5f68295fc1 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -5.1.0-SNAPSHOT \ No newline at end of file +6.0.0-SNAPSHOT \ No newline at end of file From 475bba0cb4e5f37c94de0c02d02f7c2adc4a84ce Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Tue, 17 Apr 2018 14:16:10 +0200 Subject: [PATCH 02/47] Query-based sync are now the default mode for Sync (#5893) --- CHANGELOG.md | 7 +++ .../io/realm/ObjectLevelPermissionsTest.java | 1 - .../java/io/realm/SyncConfigurationTests.java | 26 +++++--- .../java/io/realm/SyncManagerTests.java | 5 +- .../java/io/realm/SyncUserTests.java | 5 +- .../java/io/realm/SyncedRealmTests.java | 2 +- .../src/main/java/io/realm/Realm.java | 8 +-- .../java/io/realm/PermissionManager.java | 3 + .../java/io/realm/SyncConfiguration.java | 63 +++++++++++++------ .../internal/SyncObjectServerFacade.java | 4 +- .../java/io/realm/SSLConfigurationTests.java | 8 +++ .../java/io/realm/SyncSessionTests.java | 14 ++++- .../io/realm/SyncedRealmIntegrationTests.java | 10 ++- .../EncryptedSynchronizedRealmTests.java | 4 ++ ...ObjectLevelPermissionIntegrationTests.java | 4 +- .../objectserver/ProcessCommitTests.java | 4 ++ .../objectserver/ProgressListenerTests.java | 11 +++- ...yncTests.java => QueryBasedSyncTests.java} | 11 ++-- 18 files changed, 138 insertions(+), 52 deletions(-) rename realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/{PartialSyncTests.java => QueryBasedSyncTests.java} (97%) diff --git a/CHANGELOG.md b/CHANGELOG.md index fa6aa8705c..af3a9dfc25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 6.0.0 (YYYY-MM-DD) + +### Breaking Changes + +* [ObjectServer] Partial sync is now the default mode of synchronization. `SyncConfiguration.Builder.partialRealm()` has been replaced by `SyncConfiguration.Builder.fullSynchronization()`. +* [ObjectServer] `SyncConfiguration.isPartialRealm()` has been replaced by `SyncConfiguration.isFullySynchronizedRealm()`. + ## 5.1.0 (YYYY-MM-DD) ### Enhancements diff --git a/realm/realm-library/src/androidTestObjectServer/java/io/realm/ObjectLevelPermissionsTest.java b/realm/realm-library/src/androidTestObjectServer/java/io/realm/ObjectLevelPermissionsTest.java index 7c156bf79d..ed75f54e79 100644 --- a/realm/realm-library/src/androidTestObjectServer/java/io/realm/ObjectLevelPermissionsTest.java +++ b/realm/realm-library/src/androidTestObjectServer/java/io/realm/ObjectLevelPermissionsTest.java @@ -69,7 +69,6 @@ public static class TestModule { public void setUp() { user = createTestUser(); configuration = new SyncConfiguration.Builder(user, REALM_URI) - .partialRealm() .modules(new TestModule()) .build(); realm = Realm.getInstance(configuration); diff --git a/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncConfigurationTests.java b/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncConfigurationTests.java index bf05c006ab..4bac7b88a6 100644 --- a/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncConfigurationTests.java +++ b/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncConfigurationTests.java @@ -20,6 +20,7 @@ import android.support.test.runner.AndroidJUnit4; import org.junit.After; +import org.junit.Before; import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; @@ -61,12 +62,17 @@ public class SyncConfigurationTests { @Rule public final ExpectedException thrown = ExpectedException.none(); + @Before + public void setUp() { + Realm.init(InstrumentationRegistry.getTargetContext()); + } + @After public void tearDown() { - for (SyncUser syncUser : SyncUser.all().values()) { - syncUser.logOut(); + UserStore userStore = SyncManager.getUserStore(); + for (SyncUser syncUser : userStore.allUsers()) { + userStore.remove(syncUser.getIdentity(), syncUser.getAuthenticationUrl().toString()); } - SyncManager.reset(); } @Test @@ -452,9 +458,13 @@ public void multipleUsersReferenceSameRealm() { SyncUser user1 = createNamedTestUser("user1"); SyncUser user2 = createNamedTestUser("user2"); String sharedUrl = "realm://ros.realm.io/42/default"; - SyncConfiguration config1 = new SyncConfiguration.Builder(user1, sharedUrl).modules(new StringOnlyModule()).build(); + SyncConfiguration config1 = new SyncConfiguration.Builder(user1, sharedUrl) + .modules(new StringOnlyModule()) + .build(); Realm realm1 = Realm.getInstance(config1); - SyncConfiguration config2 = new SyncConfiguration.Builder(user2, sharedUrl).modules(new StringOnlyModule()).build(); + SyncConfiguration config2 = new SyncConfiguration.Builder(user2, sharedUrl) + .modules(new StringOnlyModule()) + .build(); Realm realm2 = null; // Verify that two different configurations can be used for the same URL @@ -513,14 +523,14 @@ public void automaticWithUser_throwsIfNullOrInvalid() { } @Test - public void automatic_isPartial() { + public void automatic_isFullySynchronized() { SyncUser user = SyncTestUtils.createTestUser(); SyncConfiguration config = SyncConfiguration.automatic(); - assertTrue(config.isPartialRealm()); + assertFalse(config.isFullySynchronizedRealm()); config = SyncConfiguration.automatic(user); - assertTrue(config.isPartialRealm()); + assertFalse(config.isFullySynchronizedRealm()); } @Test diff --git a/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncManagerTests.java b/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncManagerTests.java index 89c13dd672..7b56e85a34 100644 --- a/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncManagerTests.java +++ b/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncManagerTests.java @@ -83,7 +83,10 @@ public boolean isActive(String identity, String authenticationUrl) { @After public void tearDown() { UserFactory.logoutAllUsers(); - SyncManager.reset(); + UserStore userStore = SyncManager.getUserStore(); + for (SyncUser syncUser : userStore.allUsers()) { + userStore.remove(syncUser.getIdentity(), syncUser.getAuthenticationUrl().toString()); + } } @Test diff --git a/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncUserTests.java b/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncUserTests.java index 603eae46ae..9c4f07777c 100644 --- a/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncUserTests.java +++ b/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncUserTests.java @@ -103,7 +103,10 @@ public static void initUserStore() { @Before public void setUp() { - SyncManager.reset(); + UserStore userStore = SyncManager.getUserStore(); + for (SyncUser syncUser : userStore.allUsers()) { + userStore.remove(syncUser.getIdentity(), syncUser.getAuthenticationUrl().toString()); + } } @After diff --git a/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncedRealmTests.java b/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncedRealmTests.java index 6c6cab9b26..93e5974d27 100644 --- a/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncedRealmTests.java +++ b/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncedRealmTests.java @@ -62,7 +62,6 @@ private Realm getNormalRealm() { private Realm getPartialRealm() { SyncConfiguration config = configFactory.createSyncConfigurationBuilder(SyncTestUtils.createTestUser(), "http://foo.com/fullsync") - .partialRealm() .build(); realm = Realm.getInstance(config); return realm; @@ -70,6 +69,7 @@ private Realm getPartialRealm() { private Realm getFullySyncRealm() { SyncConfiguration config = configFactory.createSyncConfigurationBuilder(SyncTestUtils.createTestUser(), "http://foo.com/fullsync") + .fullSynchronization() .build(); realm = Realm.getInstance(config); return realm; diff --git a/realm/realm-library/src/main/java/io/realm/Realm.java b/realm/realm-library/src/main/java/io/realm/Realm.java index 3bf2ba64fd..7ff6e42b79 100644 --- a/realm/realm-library/src/main/java/io/realm/Realm.java +++ b/realm/realm-library/src/main/java/io/realm/Realm.java @@ -1590,7 +1590,7 @@ public void run() { * Deletes all objects of the specified class from the Realm. * * @param clazz the class which objects should be removed. - * @throws IllegalStateException if the corresponding Realm is a partially synchronized Realm, is + * @throws IllegalStateException if the corresponding Realm is a query-based synchronized Realm, is * closed or called from an incorrect thread. */ public void delete(Class clazz) { @@ -1728,7 +1728,7 @@ public static boolean compactRealm(RealmConfiguration configuration) { * @return a {@link RealmAsyncTask} representing a cancellable task. * @throws IllegalArgumentException if no {@code subscriptionName} or {@code callback} was provided. * @throws IllegalStateException if called on a non-looper thread. - * @throws UnsupportedOperationException if the Realm is not a partially synchronized Realm. + * @throws UnsupportedOperationException if the Realm is not a query-based synchronized Realm. */ @Beta public RealmAsyncTask unsubscribeAsync(String subscriptionName, Realm.UnsubscribeCallback callback) { @@ -1741,7 +1741,7 @@ public RealmAsyncTask unsubscribeAsync(String subscriptionName, Realm.Unsubscrib } sharedRealm.capabilities.checkCanDeliverNotification("This method is only available from a Looper thread."); if (!ObjectServerFacade.getSyncFacadeIfPossible().isPartialRealm(configuration)) { - throw new UnsupportedOperationException("Realm is not a partially synchronized Realm: " + configuration.getPath()); + throw new UnsupportedOperationException("Realm is fully synchronized Realm. This method is only available when using query-based synchronization: " + configuration.getPath()); } return executeTransactionAsync(new Transaction() { @@ -1944,7 +1944,7 @@ interface OnError { } /** - * Interface used when canceling partial sync subscriptions. + * Interface used when canceling query-based sync subscriptions. * * @see #unsubscribeAsync(String, UnsubscribeCallback) */ diff --git a/realm/realm-library/src/objectServer/java/io/realm/PermissionManager.java b/realm/realm-library/src/objectServer/java/io/realm/PermissionManager.java index c9471a7df1..9c7772eea5 100644 --- a/realm/realm-library/src/objectServer/java/io/realm/PermissionManager.java +++ b/realm/realm-library/src/objectServer/java/io/realm/PermissionManager.java @@ -180,6 +180,7 @@ private PermissionManager(SyncUser user) { threadId = Thread.currentThread().getId(); managementRealmConfig = new SyncConfiguration.Builder( user, getRealmUrl(RealmType.MANAGEMENT_REALM, user.getAuthenticationUrl())) + .fullSynchronization() .errorHandler(new SyncSession.ErrorHandler() { @Override public void onError(SyncSession session, ObjectServerError error) { @@ -194,6 +195,7 @@ public void onError(SyncSession session, ObjectServerError error) { permissionRealmConfig = new SyncConfiguration.Builder( user, getRealmUrl(RealmType.PERMISSION_REALM, user.getAuthenticationUrl())) + .fullSynchronization() .errorHandler(new SyncSession.ErrorHandler() { @Override public void onError(SyncSession session, ObjectServerError error) { @@ -211,6 +213,7 @@ public void onError(SyncSession session, ObjectServerError error) { defaultPermissionRealmConfig = new SyncConfiguration.Builder( user, getRealmUrl(RealmType.DEFAULT_PERMISSION_REALM, user.getAuthenticationUrl())) + .fullSynchronization() .errorHandler(new SyncSession.ErrorHandler() { @Override public void onError(SyncSession session, ObjectServerError error) { diff --git a/realm/realm-library/src/objectServer/java/io/realm/SyncConfiguration.java b/realm/realm-library/src/objectServer/java/io/realm/SyncConfiguration.java index 7cbf711b85..a6319c0fef 100644 --- a/realm/realm-library/src/objectServer/java/io/realm/SyncConfiguration.java +++ b/realm/realm-library/src/objectServer/java/io/realm/SyncConfiguration.java @@ -46,7 +46,7 @@ import io.realm.rx.RxObservableFactory; /** - * An {@link SyncConfiguration} is used to setup a Realm that can be synchronized between devices using the Realm + * A {@link SyncConfiguration} is used to setup a Realm that can be synchronized between devices using the Realm * Object Server. *

* A valid {@link SyncUser} is required to create a {@link SyncConfiguration}. See {@link SyncCredentials} and @@ -56,13 +56,32 @@ * A minimal {@link SyncConfiguration} can be found below. *

  * {@code
- * SyncConfiguration config = new SyncConfiguration.Builder(context)
- *   .serverUrl("realm://objectserver.realm.io/~/default")
- *   .user(myUser)
- *   .build();
+ * SyncUser user = SyncUser.current();
+ * String url = "realm://myinstance.cloud.realm.io/default";
+ * SyncConfiguration config = new SyncConfiguration.Builder(user, url).build();
  * }
  * 
* + * Synchronized Realms come in two forms: + * + *

* Synchronized Realms only support additive migrations which can be detected and performed automatically, so * the following builder options are not accessible compared to a normal Realm: * @@ -73,6 +92,9 @@ * * Synchronized Realms are created by using {@link Realm#getInstance(RealmConfiguration)} and * {@link Realm#getDefaultInstance()} like ordinary unsynchronized Realms. + * + * @see The docs for more + * information about the two types of synchronization. */ public class SyncConfiguration extends RealmConfiguration { @@ -224,7 +246,6 @@ public static SyncConfiguration automatic(SyncUser user) { private static SyncConfiguration getDefaultConfig(SyncUser user) { return new SyncConfiguration.Builder(user, createUrl(user)) - .partialRealm() .build(); } @@ -430,16 +451,12 @@ public OsRealmConfig.SyncSessionStopPolicy getSessionStopPolicy() { } /** - * Whether this configuration is for a partial synchronization Realm. - *

- * Partial synchronization allows a synchronized Realm to be opened in such a way that - * only objects queried by the user are synchronized to the device. + * Returns whether this configuration is for a fully synchronized Realm or not. * - * @return {@code true} to open a partial synchronization Realm {@code false} otherwise. - * @see Builder#partialRealm() for more details. + * @see Builder#fullSynchronization() for more details. */ - public boolean isPartialRealm() { - return isPartial; + public boolean isFullySynchronizedRealm() { + return !isPartial; } /** @@ -477,7 +494,7 @@ public static final class Builder { @Nullable private String serverCertificateFilePath; private OsRealmConfig.SyncSessionStopPolicy sessionStopPolicy = OsRealmConfig.SyncSessionStopPolicy.AFTER_CHANGES_UPLOADED; - private boolean isPartial = false; + private boolean isPartial = true; // Partial Synchronization is enabled by default /** * Creates an instance of the Builder for the SyncConfiguration. *

@@ -941,11 +958,17 @@ public SyncConfiguration.Builder readOnly() { } /** - * Setting this will open a partially synchronized Realm. - * @see #isPartialRealm() + * Define this Realm as a fully synchronized Realm. + *

+ * Full synchronization, unlike the default query-based synchronization, will transparently + * synchronize the entire Realm without needing to query for the data. This option is + * useful if the serverside Realm is small and all the data in the Realm should be + * available to the user. + * + * @see #isFullySynchronizedRealm() () */ - public SyncConfiguration.Builder partialRealm() { - this.isPartial = true; + public SyncConfiguration.Builder fullSynchronization() { + this.isPartial = false; return this; } @@ -1069,7 +1092,7 @@ public SyncConfiguration build() { } } - // If partial sync is enabled, also add support for Object Level Permissions + // If query based sync is enabled, also add support for Object Level Permissions if (isPartial) { addModule(new ObjectPermissionsModule()); } diff --git a/realm/realm-library/src/objectServer/java/io/realm/internal/SyncObjectServerFacade.java b/realm/realm-library/src/objectServer/java/io/realm/internal/SyncObjectServerFacade.java index b0ac440bbf..fc34b1df5d 100644 --- a/realm/realm-library/src/objectServer/java/io/realm/internal/SyncObjectServerFacade.java +++ b/realm/realm-library/src/objectServer/java/io/realm/internal/SyncObjectServerFacade.java @@ -94,7 +94,7 @@ public Object[] getUserAndServerUrl(RealmConfiguration config) { String syncRealmAuthUrl = user.getAuthenticationUrl().toString(); String rosSerializedUser = user.toJson(); byte sessionStopPolicy = syncConfig.getSessionStopPolicy().getNativeValue(); - return new Object[]{rosUserIdentity, rosServerUrl, syncRealmAuthUrl, rosSerializedUser, syncConfig.syncClientValidateSsl(), syncConfig.getServerCertificateFilePath(), sessionStopPolicy, syncConfig.isPartialRealm()}; + return new Object[]{rosUserIdentity, rosServerUrl, syncRealmAuthUrl, rosSerializedUser, syncConfig.syncClientValidateSsl(), syncConfig.getServerCertificateFilePath(), sessionStopPolicy, !syncConfig.isFullySynchronizedRealm()}; } else { return new Object[8]; } @@ -180,7 +180,7 @@ public boolean wasDownloadInterrupted(Throwable throwable) { public boolean isPartialRealm(RealmConfiguration configuration) { if (configuration instanceof SyncConfiguration) { SyncConfiguration syncConfig = (SyncConfiguration) configuration; - return syncConfig.isPartialRealm(); + return !syncConfig.isFullySynchronizedRealm(); } return false; diff --git a/realm/realm-library/src/syncIntegrationTest/java/io/realm/SSLConfigurationTests.java b/realm/realm-library/src/syncIntegrationTest/java/io/realm/SSLConfigurationTests.java index a899730c7e..08c58ce930 100644 --- a/realm/realm-library/src/syncIntegrationTest/java/io/realm/SSLConfigurationTests.java +++ b/realm/realm-library/src/syncIntegrationTest/java/io/realm/SSLConfigurationTests.java @@ -58,6 +58,7 @@ public void trustedRootCA() throws InterruptedException { // 1. Copy a valid Realm to the server //noinspection unchecked final SyncConfiguration syncConfig = configurationFactory.createSyncConfigurationBuilder(user, Constants.USER_REALM) + .fullSynchronization() .schema(StringOnly.class) .build(); Realm realm = Realm.getInstance(syncConfig); @@ -76,6 +77,7 @@ public void trustedRootCA() throws InterruptedException { user = SyncUser.logIn(SyncCredentials.usernamePassword(username, password), Constants.AUTH_URL); //noinspection unchecked SyncConfiguration syncConfigSSL = configurationFactory.createSyncConfigurationBuilder(user, Constants.USER_REALM_SECURE) + .fullSynchronization() .name("useSsl") .schema(StringOnly.class) .waitForInitialRemoteData() @@ -103,6 +105,7 @@ public void withoutSSLVerification() throws InterruptedException { // 1. Copy a valid Realm to the server //noinspection unchecked final SyncConfiguration syncConfig = configurationFactory.createSyncConfigurationBuilder(user, Constants.USER_REALM) + .fullSynchronization() .schema(StringOnly.class) .build(); Realm realm = Realm.getInstance(syncConfig); @@ -121,6 +124,7 @@ public void withoutSSLVerification() throws InterruptedException { user = SyncUser.logIn(SyncCredentials.usernamePassword(username, password), Constants.AUTH_URL); //noinspection unchecked SyncConfiguration syncConfigSSL = configurationFactory.createSyncConfigurationBuilder(user, Constants.USER_REALM_SECURE) + .fullSynchronization() .name("useSsl") .schema(StringOnly.class) .waitForInitialRemoteData() @@ -238,6 +242,7 @@ public void combiningTrustedRootCA_and_disableSSLVerification() throws Interrupt // 1. Copy a valid Realm to the server using ssl_verify_path option //noinspection unchecked final SyncConfiguration syncConfigWithCertificate = configurationFactory.createSyncConfigurationBuilder(user, Constants.USER_REALM_SECURE) + .fullSynchronization() .schema(StringOnly.class) .trustedRootCA("trusted_ca.pem") .build(); @@ -257,6 +262,7 @@ public void combiningTrustedRootCA_and_disableSSLVerification() throws Interrupt user = SyncUser.logIn(SyncCredentials.usernamePassword(username, password), Constants.AUTH_URL); //noinspection unchecked SyncConfiguration syncConfigDisableSSL = configurationFactory.createSyncConfigurationBuilder(user, Constants.USER_REALM_SECURE) + .fullSynchronization() .name("useSsl") .schema(StringOnly.class) .waitForInitialRemoteData() @@ -288,6 +294,7 @@ public void sslVerifyCallback_isUsed() throws InterruptedException { // 1. Copy a valid Realm to the server using ssl_verify_path option //noinspection unchecked final SyncConfiguration syncConfig = configurationFactory.createSyncConfigurationBuilder(user, Constants.USER_REALM) + .fullSynchronization() .schema(StringOnly.class) .build(); Realm realm = Realm.getInstance(syncConfig); @@ -307,6 +314,7 @@ public void sslVerifyCallback_isUsed() throws InterruptedException { //noinspection unchecked SyncConfiguration syncConfigSecure = configurationFactory.createSyncConfigurationBuilder(user, Constants.USER_REALM_SECURE) .name("useSsl") + .fullSynchronization() .schema(StringOnly.class) .waitForInitialRemoteData() .build(); diff --git a/realm/realm-library/src/syncIntegrationTest/java/io/realm/SyncSessionTests.java b/realm/realm-library/src/syncIntegrationTest/java/io/realm/SyncSessionTests.java index 6c73bcd8a2..7ccccc9e46 100644 --- a/realm/realm-library/src/syncIntegrationTest/java/io/realm/SyncSessionTests.java +++ b/realm/realm-library/src/syncIntegrationTest/java/io/realm/SyncSessionTests.java @@ -79,6 +79,7 @@ public void getState_loggedOut() { SyncUser user = UserFactory.createUniqueUser(Constants.AUTH_URL); SyncConfiguration syncConfiguration = configFactory .createSyncConfigurationBuilder(user, Constants.SYNC_SERVER_URL) + .fullSynchronization() .build(); Realm realm = Realm.getInstance(syncConfiguration); @@ -98,9 +99,11 @@ public void uploadDownloadAllChanges() throws InterruptedException { SyncUser adminUser = UserFactory.createAdminUser(Constants.AUTH_URL); SyncConfiguration userConfig = configFactory .createSyncConfigurationBuilder(user, Constants.SYNC_SERVER_URL) + .fullSynchronization() .build(); SyncConfiguration adminConfig = configFactory .createSyncConfigurationBuilder(adminUser, userConfig.getServerUrl().toString()) + .fullSynchronization() .build(); Realm userRealm = Realm.getInstance(userConfig); @@ -123,9 +126,11 @@ public void interruptWaits() throws InterruptedException { SyncUser adminUser = UserFactory.createAdminUser(Constants.AUTH_URL); final SyncConfiguration userConfig = configFactory .createSyncConfigurationBuilder(user, Constants.SYNC_SERVER_URL) + .fullSynchronization() .build(); final SyncConfiguration adminConfig = configFactory .createSyncConfigurationBuilder(adminUser, userConfig.getServerUrl().toString()) + .fullSynchronization() .build(); Thread t = new Thread(new Runnable() { @@ -227,13 +232,14 @@ public void logout_sameSyncUserMultipleSessions() { // A Realm that was opened before a user logged out should be able to resume uploading if the user logs back in. @Test - public void logBackResumeUpload() throws InterruptedException, NoSuchFieldException, IllegalAccessException { + public void logBackResumeUpload() throws InterruptedException { final String uniqueName = UUID.randomUUID().toString(); SyncCredentials credentials = SyncCredentials.usernamePassword(uniqueName, "password", true); SyncUser user = SyncUser.logIn(credentials, Constants.AUTH_URL); final SyncConfiguration syncConfiguration = configFactory .createSyncConfigurationBuilder(user, Constants.SYNC_SERVER_URL) + .fullSynchronization() .modules(new StringOnlyModule()) .waitForInitialRemoteData() .build(); @@ -275,6 +281,7 @@ public void run() { SyncConfiguration adminConfig = configurationFactory.createSyncConfigurationBuilder(adminUser, syncConfiguration.getServerUrl().toString()) .modules(new StringOnlyModule()) + .fullSynchronization() .waitForInitialRemoteData() .build(); final Realm adminRealm = Realm.getInstance(adminConfig); @@ -322,6 +329,7 @@ public void uploadChangesWhenRealmOutOfScope() throws InterruptedException { final SyncConfiguration syncConfiguration = configFactory .createSyncConfigurationBuilder(user, Constants.SYNC_SERVER_URL) + .fullSynchronization() .sessionStopPolicy(OsRealmConfig.SyncSessionStopPolicy.AFTER_CHANGES_UPLOADED) .modules(new StringOnlyModule()) .build(); @@ -348,6 +356,7 @@ public void run() { SyncUser admin = UserFactory.createAdminUser(Constants.AUTH_URL); SyncConfiguration adminConfig = configurationFactory.createSyncConfigurationBuilder(admin, syncConfiguration.getServerUrl().toString()) + .fullSynchronization() .modules(new StringOnlyModule()) .build(); final Realm adminRealm = Realm.getInstance(adminConfig); @@ -383,6 +392,7 @@ public void downloadChangesWhenRealmOutOfScope() throws InterruptedException { final SyncConfiguration syncConfiguration = configFactory .createSyncConfigurationBuilder(user, Constants.SYNC_SERVER_URL) + .fullSynchronization() .modules(new StringOnlyModule()) .build(); Realm realm = Realm.getInstance(syncConfiguration); @@ -417,6 +427,7 @@ public void run() { SyncUser adminUser = SyncUser.logIn(credentialsAdmin, Constants.AUTH_URL); SyncConfiguration adminConfig = configurationFactory.createSyncConfigurationBuilder(adminUser, syncConfiguration.getServerUrl().toString()) + .fullSynchronization() .modules(new StringOnlyModule()) .waitForInitialRemoteData() .build(); @@ -460,6 +471,7 @@ public void clientReset_manualTriggerAllowSessionToRestart() { final AtomicReference configRef = new AtomicReference<>(null); final SyncConfiguration config = configFactory.createSyncConfigurationBuilder(user, Constants.USER_REALM) .directory(looperThread.getRoot()) + .fullSynchronization() .errorHandler(new SyncSession.ErrorHandler() { @Override public void onError(SyncSession session, ObjectServerError error) { diff --git a/realm/realm-library/src/syncIntegrationTest/java/io/realm/SyncedRealmIntegrationTests.java b/realm/realm-library/src/syncIntegrationTest/java/io/realm/SyncedRealmIntegrationTests.java index 24cab081af..495af01ff6 100644 --- a/realm/realm-library/src/syncIntegrationTest/java/io/realm/SyncedRealmIntegrationTests.java +++ b/realm/realm-library/src/syncIntegrationTest/java/io/realm/SyncedRealmIntegrationTests.java @@ -50,8 +50,8 @@ @RunWith(AndroidJUnit4.class) public class SyncedRealmIntegrationTests extends StandardIntegrationTest { - @Test + @RunTestInLooperThread public void loginLogoutResumeSyncing() throws InterruptedException { String username = UUID.randomUUID().toString(); String password = "password"; @@ -59,6 +59,7 @@ public void loginLogoutResumeSyncing() throws InterruptedException { SyncConfiguration config = new SyncConfiguration.Builder(user, Constants.USER_REALM) .schema(StringOnly.class) + .fullSynchronization() .sessionStopPolicy(OsRealmConfig.SyncSessionStopPolicy.IMMEDIATELY) .build(); @@ -84,6 +85,7 @@ public void loginLogoutResumeSyncing() throws InterruptedException { user = SyncUser.logIn(SyncCredentials.usernamePassword(username, password, false), Constants.AUTH_URL); SyncConfiguration config2 = new SyncConfiguration.Builder(user, Constants.USER_REALM) + .fullSynchronization() .schema(StringOnly.class) .build(); @@ -92,6 +94,7 @@ public void loginLogoutResumeSyncing() throws InterruptedException { realm2.refresh(); assertEquals(1, realm2.where(StringOnly.class).count()); realm2.close(); + looperThread.testComplete(); } @Test @@ -99,6 +102,7 @@ public void loginLogoutResumeSyncing() throws InterruptedException { public void waitForInitialRemoteData_mainThreadThrows() { final SyncUser user = SyncTestUtils.createTestUser(Constants.AUTH_URL); SyncConfiguration config = new SyncConfiguration.Builder(user, Constants.USER_REALM) + .fullSynchronization() .waitForInitialRemoteData() .build(); @@ -124,6 +128,7 @@ public void waitForInitialRemoteData() throws InterruptedException { // 1. Copy a valid Realm to the server (and pray it does it within 10 seconds) final SyncConfiguration configOld = configurationFactory.createSyncConfigurationBuilder(user, Constants.USER_REALM) + .fullSynchronization() .schema(StringOnly.class) .sessionStopPolicy(OsRealmConfig.SyncSessionStopPolicy.IMMEDIATELY) .build(); @@ -145,6 +150,7 @@ public void execute(Realm realm) { user = SyncUser.logIn(SyncCredentials.usernamePassword(username, password), Constants.AUTH_URL); SyncConfiguration config = new SyncConfiguration.Builder(user, Constants.USER_REALM) .name("newRealm") + .fullSynchronization() .schema(StringOnly.class) .waitForInitialRemoteData() .build(); @@ -244,6 +250,7 @@ public void waitForInitialRemoteData_readOnlyTrue() throws InterruptedException // 1. Copy a valid Realm to the server (and pray it does it within 10 seconds) final SyncConfiguration configOld = configurationFactory.createSyncConfigurationBuilder(user, Constants.USER_REALM) + .fullSynchronization() .schema(StringOnly.class) .build(); Realm realm = Realm.getInstance(configOld); @@ -264,6 +271,7 @@ public void execute(Realm realm) { user = SyncUser.logIn(SyncCredentials.usernamePassword(username, password, false), Constants.AUTH_URL); final SyncConfiguration configNew = configurationFactory.createSyncConfigurationBuilder(user, Constants.USER_REALM) .name("newRealm") + .fullSynchronization() .waitForInitialRemoteData() .readOnly() .schema(StringOnly.class) diff --git a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/EncryptedSynchronizedRealmTests.java b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/EncryptedSynchronizedRealmTests.java index 7c8b64a2f7..c0e1ae5cea 100644 --- a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/EncryptedSynchronizedRealmTests.java +++ b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/EncryptedSynchronizedRealmTests.java @@ -48,6 +48,7 @@ public void setEncryptionKey_canReOpenRealmWithoutKey() { final byte[] randomKey = TestHelper.getRandomKey(); SyncConfiguration configWithEncryption = configurationFactory.createSyncConfigurationBuilder(user, Constants.USER_REALM) + .fullSynchronization() .modules(new StringOnlyModule()) .waitForInitialRemoteData() .errorHandler(new SyncSession.ErrorHandler() { @@ -75,6 +76,7 @@ public void onError(SyncSession session, ObjectServerError error) { // fail user = SyncUser.logIn(SyncCredentials.usernamePassword(username, password, false), Constants.AUTH_URL); SyncConfiguration configWithoutEncryption = configurationFactory.createSyncConfigurationBuilder(user, Constants.USER_REALM) + .fullSynchronization() .name("newName") .modules(new StringOnlyModule()) .waitForInitialRemoteData() @@ -165,6 +167,7 @@ public void setEncryptionKey_differentClientsWithDifferentKeys() throws Interrup final byte[] randomKey = TestHelper.getRandomKey(); SyncConfiguration configWithEncryption = configurationFactory.createSyncConfigurationBuilder(user, Constants.USER_REALM) + .fullSynchronization() .modules(new StringOnlyModule()) .waitForInitialRemoteData() .errorHandler(new SyncSession.ErrorHandler() { @@ -195,6 +198,7 @@ public void onError(SyncSession session, ObjectServerError error) { final byte[] adminRandomKey = TestHelper.getRandomKey(); SyncConfiguration adminConfigWithEncryption = configurationFactory.createSyncConfigurationBuilder(adminUser, configWithEncryption.getServerUrl().toString()) + .fullSynchronization() .modules(new StringOnlyModule()) .waitForInitialRemoteData() .errorHandler(new SyncSession.ErrorHandler() { diff --git a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ObjectLevelPermissionIntegrationTests.java b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ObjectLevelPermissionIntegrationTests.java index 29c9c89cbe..437957706f 100644 --- a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ObjectLevelPermissionIntegrationTests.java +++ b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ObjectLevelPermissionIntegrationTests.java @@ -72,7 +72,6 @@ public void getPrivileges_serverDefaults() throws InterruptedException { SyncUser user = UserFactory.createUniqueUser(Constants.AUTH_URL); SyncConfiguration syncConfig = configurationFactory.createSyncConfigurationBuilder(user, Constants.DEFAULT_REALM) .modules(schemaModule) - .partialRealm() .build(); Realm realm = Realm.getInstance(syncConfig); @@ -119,7 +118,6 @@ public void restrictAccessToOwner() throws InterruptedException { SyncConfiguration user1SyncConfig = configurationFactory .createSyncConfigurationBuilder(user1, Constants.DEFAULT_REALM) .modules(schemaModules) - .partialRealm() .build(); Realm user1Realm = Realm.getInstance(user1SyncConfig); user1Realm.beginTransaction(); @@ -149,6 +147,7 @@ public void restrictAccessToOwner() throws InterruptedException { // Connect with admin user and verify that user1 object is visible (non-partial Realm) SyncUser adminUser = UserFactory.createNicknameUser(Constants.AUTH_URL, "admin2", true); SyncConfiguration adminConfig = configurationFactory.createSyncConfigurationBuilder(adminUser, Constants.DEFAULT_REALM) + .fullSynchronization() .modules(schemaModules) .waitForInitialRemoteData() .build(); @@ -166,7 +165,6 @@ public void restrictAccessToOwner() throws InterruptedException { SyncUser user2 = UserFactory.createUniqueUser(Constants.AUTH_URL); SyncConfiguration syncConfig2 = configurationFactory.createSyncConfigurationBuilder(user2, Constants.DEFAULT_REALM) .modules(schemaModules) - .partialRealm() .build(); Realm user2Realm = Realm.getInstance(syncConfig2); looperThread.closeAfterTest(user2Realm); diff --git a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProcessCommitTests.java b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProcessCommitTests.java index 214af8c97d..7e9ed18b78 100644 --- a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProcessCommitTests.java +++ b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProcessCommitTests.java @@ -74,6 +74,7 @@ protected void run() { String realmUrl = Constants.SYNC_SERVER_URL; final SyncConfiguration syncConfig = new SyncConfiguration.Builder(user, realmUrl) + .fullSynchronization() .modules(new ProcessCommitTestsModule()) .directory(getService().getRoot()) .build(); @@ -125,6 +126,7 @@ public void expectSimpleCommit() { final SyncUser user = UserFactory.getInstance().createDefaultUser(Constants.AUTH_URL); String realmUrl = Constants.SYNC_SERVER_URL; final SyncConfiguration syncConfig = new SyncConfiguration.Builder(user,realmUrl) + .fullSynchronization() .modules(new ProcessCommitTestsModule()) .directory(looperThread.getRoot()) .build(); @@ -158,6 +160,7 @@ protected void run() { String realmUrl = Constants.SYNC_SERVER_URL; final SyncConfiguration syncConfig = new SyncConfiguration.Builder(user, realmUrl) + .fullSynchronization() .modules(new ProcessCommitTestsModule()) .directory(getService().getRoot()) .name(UUID.randomUUID().toString() + ".realm") @@ -205,6 +208,7 @@ public void expectALot() throws Throwable { final SyncUser user = UserFactory.getInstance().createDefaultUser(Constants.AUTH_URL); String realmUrl = Constants.SYNC_SERVER_URL; final SyncConfiguration syncConfig = new SyncConfiguration.Builder(user,realmUrl) + .fullSynchronization() .modules(new ProcessCommitTestsModule()) .directory(looperThread.getRoot()) .build(); diff --git a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java index 5efddd5eb7..228a5f08e1 100644 --- a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java +++ b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java @@ -61,7 +61,9 @@ public class ProgressListenerTests extends StandardIntegrationTest { @Nonnull private SyncConfiguration createSyncConfig() { SyncUser user = UserFactory.createAdminUser(Constants.AUTH_URL); - return configFactory.createSyncConfigurationBuilder(user, Constants.SYNC_SERVER_URL).build(); + return configFactory.createSyncConfigurationBuilder(user, Constants.SYNC_SERVER_URL) + .fullSynchronization() + .build(); } private void writeSampleData(Realm realm) { @@ -135,11 +137,14 @@ public void downloadProgressListener_changesOnly() { final CountDownLatch allChangesDownloaded = new CountDownLatch(1); SyncUser userWithData = UserFactory.createUniqueUser(Constants.AUTH_URL); SyncConfiguration userWithDataConfig = configFactory.createSyncConfigurationBuilder(userWithData, Constants.USER_REALM) + .fullSynchronization() .build(); URI serverUrl = createRemoteData(userWithDataConfig); SyncUser adminUser = UserFactory.createAdminUser(Constants.AUTH_URL); - final SyncConfiguration config = configFactory.createSyncConfigurationBuilder(adminUser, serverUrl.toString()).build(); + final SyncConfiguration config = configFactory.createSyncConfigurationBuilder(adminUser, serverUrl.toString()) + .fullSynchronization() + .build(); Realm realm = Realm.getInstance(config); SyncSession session = SyncManager.getSession(config); session.addDownloadProgressListener(ProgressMode.CURRENT_CHANGES, new ProgressListener() { @@ -164,6 +169,7 @@ public void downloadProgressListener_indefinitely() throws InterruptedException final SyncUser userWithData = UserFactory.createUniqueUser(Constants.AUTH_URL); final SyncConfiguration userWithDataConfig = configFactory.createSyncConfigurationBuilder(userWithData, Constants.USER_REALM) .name("remote") + .fullSynchronization() .build(); URI serverUrl = createRemoteData(userWithDataConfig); @@ -182,6 +188,7 @@ public void run() { SyncUser adminUser = UserFactory.createAdminUser(Constants.AUTH_URL); final SyncConfiguration adminConfig = configFactory.createSyncConfigurationBuilder(adminUser, serverUrl.toString()) .name("local") + .fullSynchronization() .build(); Realm adminRealm = Realm.getInstance(adminConfig); SyncSession session = SyncManager.getSession(adminConfig); diff --git a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/PartialSyncTests.java b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/QueryBasedSyncTests.java similarity index 97% rename from realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/PartialSyncTests.java rename to realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/QueryBasedSyncTests.java index accd479d25..6865121afa 100644 --- a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/PartialSyncTests.java +++ b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/QueryBasedSyncTests.java @@ -33,7 +33,7 @@ import static org.junit.Assert.fail; @RunWith(AndroidJUnit4.class) -public class PartialSyncTests extends StandardIntegrationTest { +public class QueryBasedSyncTests extends StandardIntegrationTest { private static final int TEST_SIZE = 10; @@ -42,7 +42,6 @@ public class PartialSyncTests extends StandardIntegrationTest { public void invalidQuery() { SyncUser user = UserFactory.createUniqueUser(Constants.AUTH_URL); final SyncConfiguration partialSyncConfig = configurationFactory.createSyncConfigurationBuilder(user, Constants.SYNC_SERVER_URL) - .partialRealm() .build(); final Realm realm = Realm.getInstance(partialSyncConfig); looperThread.closeAfterTest(realm); @@ -68,7 +67,6 @@ public void invalidQuery() { public void listQueries_doNotCreateSubscriptions() { SyncUser user = UserFactory.createUniqueUser(Constants.AUTH_URL); final SyncConfiguration partialSyncConfig = configurationFactory.createSyncConfigurationBuilder(user, Constants.SYNC_SERVER_URL) - .partialRealm() .build(); final DynamicRealm dRealm = DynamicRealm.getInstance(partialSyncConfig); @@ -159,6 +157,7 @@ public void namedSubscription() throws InterruptedException { public void partialSync_namedSubscriptionThrowsOnNonPartialRealms() { SyncUser user = UserFactory.createUniqueUser(Constants.AUTH_URL); final SyncConfiguration fullSyncConfig = configurationFactory.createSyncConfigurationBuilder(user, Constants.SYNC_SERVER_URL) + .fullSynchronization() .name("fullySynchronizedRealm") .build(); @@ -248,7 +247,7 @@ public void onError(String subscriptionName, Throwable error) { @Test @RunTestInLooperThread - public void unsubscribeAsync_nonExistingIdThrows() throws InterruptedException { + public void unsubscribeAsync_nonExistingIdThrows() { SyncUser user = UserFactory.createUniqueUser(Constants.AUTH_URL); Realm realm = getPartialRealm(user); looperThread.closeAfterTest(realm); @@ -271,7 +270,7 @@ public void onError(String subscriptionName, Throwable error) { @Test @RunTestInLooperThread - public void clearTable() throws InterruptedException { + public void clearTable() { SyncUser user = UserFactory.createUniqueUser(Constants.AUTH_URL); Realm realm = getPartialRealm(user); looperThread.closeAfterTest(realm); @@ -301,7 +300,6 @@ private Realm getPartialRealm(SyncUser user) { final SyncConfiguration partialSyncConfig = configurationFactory.createSyncConfigurationBuilder(user, Constants.SYNC_SERVER_URL) .name("partialSync") .modules(new PartialSyncModule()) - .partialRealm() .build(); return Realm.getInstance(partialSyncConfig); } @@ -309,7 +307,6 @@ private Realm getPartialRealm(SyncUser user) { private void createServerData(SyncUser user, String url) throws InterruptedException { final SyncConfiguration syncConfig = configurationFactory.createSyncConfigurationBuilder(user, url) .waitForInitialRemoteData() - .partialRealm() .modules(new PartialSyncModule()) .build(); From 68a95c5183ca1f40f91de4c05c3c63519c91dc19 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Tue, 17 Apr 2018 14:43:46 +0200 Subject: [PATCH 03/47] Use query-based sync terminology in all docs. --- .../java/io/realm/OrderedCollectionChangeSet.java | 3 +-- .../src/main/java/io/realm/RealmQuery.java | 11 ++++------- .../objectServer/java/io/realm/SyncConfiguration.java | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/realm/realm-library/src/main/java/io/realm/OrderedCollectionChangeSet.java b/realm/realm-library/src/main/java/io/realm/OrderedCollectionChangeSet.java index 97c1fcf9cd..54abab36e7 100644 --- a/realm/realm-library/src/main/java/io/realm/OrderedCollectionChangeSet.java +++ b/realm/realm-library/src/main/java/io/realm/OrderedCollectionChangeSet.java @@ -127,8 +127,7 @@ public enum State { * Returns {@code true} if the query result is considered "complete". For all local Realms, or * fully synchronized Realms, this method will always return {@code true}. *

- * This method thus only makes sense for partially synchronized Realms (as defined by setting - * {@link SyncConfiguration.Builder#partialRealm()}. + * This method thus only makes sense for query-based synchronized Realms. *

* For those Realms, data is only downloaded when queried which means that until the data is * downloaded, a local query might return a query result that would not have been possible on a diff --git a/realm/realm-library/src/main/java/io/realm/RealmQuery.java b/realm/realm-library/src/main/java/io/realm/RealmQuery.java index 67ae7832ff..82f884decc 100644 --- a/realm/realm-library/src/main/java/io/realm/RealmQuery.java +++ b/realm/realm-library/src/main/java/io/realm/RealmQuery.java @@ -1769,11 +1769,8 @@ public RealmResults findAll() { /** * Finds all objects that fulfill the query conditions. This method is only available from a Looper thread. *

- * On partially synchronized Realms, defined by setting {@link SyncConfiguration.Builder#partialRealm()}, - * this method will also create an anonymous subscription that will download all server data matching - * the query. - *

- * + * If the Realm is a Query-based synchronized Realms, this method will also create an anonymous subscription + * that will download all server data matching the query. * * @return immediately an empty {@link RealmResults}. Users need to register a listener * {@link io.realm.RealmResults#addChangeListener(RealmChangeListener)} to be notified when the query completes. @@ -1797,14 +1794,14 @@ public RealmResults findAllAsync() { /** * Finds all objects that fulfill the query condition(s). This method is only available from a Looper thread. *

- * This method is only available on partially synchronized Realms and will also create a named subscription + * This method is only available on query-based synchronized Realms and will also create a named subscription * that will synchronize all server data matching the query. Named subscriptions can be removed again by * calling {@code Realm.unsubscribe(subscriptionName}. * * @return immediately an empty {@link RealmResults}. Users need to register a listener * {@link io.realm.RealmResults#addChangeListener(RealmChangeListener)} to be notified when the query completes. * @see io.realm.RealmResults - * @throws IllegalStateException If the Realm is a not a partially synchronized Realm. + * @throws IllegalStateException If the Realm is a not a query-based synchronized Realm. */ public RealmResults findAllAsync(String subscriptionName) { realm.checkIfValid(); diff --git a/realm/realm-library/src/objectServer/java/io/realm/SyncConfiguration.java b/realm/realm-library/src/objectServer/java/io/realm/SyncConfiguration.java index a6319c0fef..f574dc7d8d 100644 --- a/realm/realm-library/src/objectServer/java/io/realm/SyncConfiguration.java +++ b/realm/realm-library/src/objectServer/java/io/realm/SyncConfiguration.java @@ -73,7 +73,7 @@ * can also be removed from the device again without being deleted on the server. * *

  • - * Full synchronization + * Full synchronization * Enable this mode by setting {@link Builder#fullSynchronization()}. In this mode * the entire Realm is synchronized in the background without having to query for * data first. This means that data generally will be available quicker but should only From 9fda114abe2d3ae30ddf0dc4be1ae6555f3ceaa3 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 7 Jun 2018 09:21:06 +0200 Subject: [PATCH 04/47] Fix bad merge --- .../src/objectServer/java/io/realm/SyncConfiguration.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/realm/realm-library/src/objectServer/java/io/realm/SyncConfiguration.java b/realm/realm-library/src/objectServer/java/io/realm/SyncConfiguration.java index 6fcf00c60f..97d9f2c8d6 100644 --- a/realm/realm-library/src/objectServer/java/io/realm/SyncConfiguration.java +++ b/realm/realm-library/src/objectServer/java/io/realm/SyncConfiguration.java @@ -965,6 +965,8 @@ public SyncConfiguration.Builder readOnly() { * @see #isFullySynchronizedRealm() () */ @Deprecated + public SyncConfiguration.Builder partialRealm() { + this.isPartial = true; return this; } From ee9817f0e412c6985843ae130099933840f579f2 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Tue, 12 Mar 2019 15:45:21 +0100 Subject: [PATCH 05/47] Preliminary work for NDK18 support --- CHANGELOG.md | 22 + README.md | 8 +- dependencies.list | 4 +- realm.properties | 2 +- realm/build.gradle | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- realm/realm-library/build.gradle | 10 +- .../realm-library/src/main/cpp/CMakeLists.txt | 30 +- .../src/main/cpp/android.toolchain.cmake | 1703 ----------------- .../src/main/cpp/io_realm_SyncSession.cpp | 30 +- .../cpp/io_realm_internal_OsRealmConfig.cpp | 4 +- .../src/main/cpp/jni_impl/android_logger.hpp | 2 +- .../src/main/cpp/jni_util/log.cpp | 4 + .../src/main/cpp/jni_util/log.hpp | 1 + realm/realm-library/src/main/cpp/object-store | 2 +- 15 files changed, 72 insertions(+), 1754 deletions(-) delete mode 100644 realm/realm-library/src/main/cpp/android.toolchain.cmake diff --git a/CHANGELOG.md b/CHANGELOG.md index de2b580084..ca19f09b83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,25 @@ +## 6.0.0(YYYY-MM-DD) + +### Breaking Changes +* Removed support for the MIPS CPU architecture. +* MinSdk has been raised from 9 to 16 + +### Enhancements +* The native code is now built with `-fstack-protector-strong`. This has no security impact when using Realm Java, but some security tools only analyzed the C++ code and reported the missing flag as a security hole. [#4553](https://github.com/realm/realm-java/issues/4553) + +### Fixed +* None + +### Compatibility +* Realm Object Server: 3.11.0 or later. +* File format: Generates Realms with format v9 (Reads and upgrades all previous formats) +* APIs are backwards compatible with all previous release of realm-java in the 6.x.y series. + +### Internal +* The NDK has been upgraded from NDK r10e to r18b. +* OpenSSL used by Realms encryption layer has been upgraded from 1.0.2k to 1.1.1a + + ## 5.9.0(2019-01-15) ### Enhancements diff --git a/README.md b/README.md index 72b599d448..f7e504f854 100644 --- a/README.md +++ b/README.md @@ -71,13 +71,13 @@ In case you don't want to use the precompiled version, you can build Realm yours * Download & install the Android SDK **Build-Tools 27.0.2**, **Android Oreo (API 27)** (for example through Android Studio’s **Android SDK Manager**). * Install CMake from SDK manager in Android Studio ("SDK Tools" -> "CMake"). - * Realm currently requires version r10e of the NDK. Download the one appropriate for your development platform, from the NDK [archive](https://developer.android.com/ndk/downloads/older_releases.html). -You may unzip the file wherever you choose. For macOS, a suggested location is `~/Library/Android`. The download will unzip as the directory `android-ndk-r10e`. + * Realm currently requires version r18b of the NDK. Download the one appropriate for your development platform, from the NDK [archive](https://developer.android.com/ndk/downloads/older_releases.html). +You may unzip the file wherever you choose. For macOS, a suggested location is `~/Library/Android`. The download will unzip as the directory `android-ndk-r18b`. * If you will be building with Android Studio, you will need to tell it to use the correct NDK. To do this, define the variable `ndk.dir` in `realm/local.properties` and assign it the full pathname of the directory that you unzipped above. Note that there is a `local.properites` in the root directory that is *not* the one that needs to be edited. ``` - ndk.dir=/Users/brian/Library/Android/android-ndk-r10e/r10e + ndk.dir=/Users//Library/Android/android-ndk-r18b ``` @@ -85,7 +85,7 @@ You may unzip the file wherever you choose. For macOS, a suggested location is ``` export ANDROID_HOME=~/Library/Android/sdk - export ANDROID_NDK_HOME=~/Library/Android/android-ndk-r10e + export ANDROID_NDK_HOME=~/Library/Android/android-ndk-r18b ``` * If you are launching Android Studio from the macOS Finder, you should also run the following two commands: diff --git a/dependencies.list b/dependencies.list index e7be39bb39..7dec8a2d95 100644 --- a/dependencies.list +++ b/dependencies.list @@ -1,7 +1,7 @@ # Realm Sync Core release used by Realm Java # https://github.com/realm/realm-sync/releases -REALM_SYNC_VERSION=3.14.13 -REALM_SYNC_SHA256=7e8934a471fa714bf672a9575cd3112470c3294d55e7a13688d04569e707b8cd +REALM_SYNC_VERSION=3.14.14-ndk18.1 +REALM_SYNC_SHA256=00bd12e400d1354335cbc56c8a1d30b48cfffaab495c390f69ddbd975c00366e # Object Server Release used by Integration tests. Installed using NPM. # Use `npm view realm-object-server versions` to get a list of available versions. diff --git a/realm.properties b/realm.properties index 1a1be59f2f..f94385d28a 100644 --- a/realm.properties +++ b/realm.properties @@ -1,2 +1,2 @@ gradleVersion=4.9 -ndkVersion=r10e +ndkVersion=18.1.5063045 diff --git a/realm/build.gradle b/realm/build.gradle index 53ffc2de3a..834996e68c 100644 --- a/realm/build.gradle +++ b/realm/build.gradle @@ -37,7 +37,7 @@ allprojects { def projectDependencies = new Properties() projectDependencies.load(new FileInputStream("${rootDir}/../dependencies.list")) - project.ext.minSdkVersion = 9 + project.ext.minSdkVersion = 21 // FIXME: Should be 16. Set to 21 currently due to OpenSSL project.ext.compileSdkVersion = 26 project.ext.buildToolsVersion = projectDependencies.get("ANDROID_BUILD_TOOLS") diff --git a/realm/gradle/wrapper/gradle-wrapper.properties b/realm/gradle/wrapper/gradle-wrapper.properties index 7dc503f149..4e974715fd 100644 --- a/realm/gradle/wrapper/gradle-wrapper.properties +++ b/realm/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/realm/realm-library/build.gradle b/realm/realm-library/build.gradle index b0e7425827..949d55a1ae 100644 --- a/realm/realm-library/build.gradle +++ b/realm/realm-library/build.gradle @@ -52,12 +52,6 @@ android { externalNativeBuild { cmake { arguments "-DREALM_CORE_DIST_DIR:STRING=${project.coreDir.getAbsolutePath()}", - // FIXME: - // This is copied from https://dl.google.com/android/repository/cmake-3.4.2909474-linux-x86_64.zip - // because of the android.toolchain.cmake shipped with Android SDK CMake 3.6 doesn't work with our - // JNI build currently (lack of lto linking support). - // This file should be removed and use the one from Android SDK cmake package when it supports lto. - "-DCMAKE_TOOLCHAIN_FILE=${project.file('src/main/cpp/android.toolchain.cmake').path}", "-DENABLE_DEBUG_CORE=$project.enableDebugCore" if (project.ccachePath) arguments "-DNDK_CCACHE=$project.ccachePath" if (project.lcachePath) arguments "-DNDK_LCACHE=$project.lcachePath" @@ -65,8 +59,8 @@ android { if (project.hasProperty('buildTargetABIs') && !project.getProperty('buildTargetABIs').trim().isEmpty()) { abiFilters(*project.getProperty('buildTargetABIs').trim().split('\\s*,\\s*')) } else { - // armeabi is not supported anymore. - abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a', 'mips' + // armeabi and MIPS are no longer supported by the NDK + abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' } } } diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index d1bd38ee21..4f260577ba 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -93,23 +93,23 @@ use_realm_core(${build_SYNC} "${REALM_CORE_DIST_DIR}" "${CORE_SOURCE_PATH}") #string(TOLOWER "${CMAKE_BUILD_TYPE}" openssl_build_TYPE) set(openssl_build_TYPE "release") # FIXME Read the openssl version from core when the core/sync release has that information. -set(openssl_VERSION "1.0.2k") +set(openssl_VERSION "1.1.1a") set(openssl_BUILD_NUMBER "1") -set(openssl_FILENAME "openssl-${openssl_build_TYPE}-${openssl_VERSION}-${openssl_BUILD_NUMBER}-Android-${ANDROID_ABI}") -set(openssl_URL "http://static.realm.io/downloads/openssl/${openssl_VERSION}/Android/${ANDROID_ABI}/${openssl_FILENAME}.tar.gz") +# set(openssl_FILENAME "openssl-${openssl_build_TYPE}-${openssl_VERSION}-${openssl_BUILD_NUMBER}-Android-${ANDROID_ABI}.tar.gz") +set (openssl_FILENAME "openssl.tgz") +set(openssl_URL "http://static.realm.io/downloads/openssl/${openssl_VERSION}/Android/${ANDROID_ABI}/${openssl_FILENAME}") message(STATUS "Downloading OpenSSL...") -file(DOWNLOAD "${openssl_URL}" "${PROJECT_BINARY_DIR}/${openssl_FILENAME}.tar.gz") +file(DOWNLOAD "${openssl_URL}" "${PROJECT_BINARY_DIR}/${openssl_FILENAME}") message(STATUS "Uncompressing OpenSSL...") -execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_BINARY_DIR}/${openssl_FILENAME}.tar.gz" - WORKING_DIRECTORY "${PROJECT_BINARY_DIR}") +execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_BINARY_DIR}/${openssl_FILENAME}" WORKING_DIRECTORY "${PROJECT_BINARY_DIR}") message(STATUS "Importing OpenSSL...") -include(${PROJECT_BINARY_DIR}/${openssl_FILENAME}/openssl.cmake) -get_target_property(openssl_include_DIR crypto INTERFACE_INCLUDE_DIRECTORIES) -get_target_property(crypto_LIB crypto IMPORTED_LOCATION) -get_target_property(ssl_LIB ssl IMPORTED_LOCATION) +include(${PROJECT_BINARY_DIR}/lib/cmake/openSSL/OpenSSLConfig.cmake) +get_target_property(openssl_include_DIR OpenSSL::Crypto INTERFACE_INCLUDE_DIRECTORIES) +get_target_property(crypto_LIB OpenSSL::Crypto IMPORTED_LOCATION) +get_target_property(ssl_LIB OpenSSL::SSL IMPORTED_LOCATION) # build application's shared lib include_directories( @@ -117,7 +117,7 @@ include_directories( ${jni_headers_PATH} ${CMAKE_SOURCE_DIR}/object-store/src) -set(ANDROID_STL "gnustl_static") +set(ANDROID_STL "c++_static") set(ANDROID_NO_UNDEFINED OFF) set(ANDROID_SO_UNDEFINED ON) @@ -142,8 +142,8 @@ endif() # -Wno-missing-field-initializers disable in object store as well. set(WARNING_CXX_FLAGS "-Werror -Wall -Wextra -pedantic -Wmissing-declarations \ -Wempty-body -Wparentheses -Wunknown-pragmas -Wunreachable-code \ - -Wno-missing-field-initializers -Wno-maybe-uninitialized -Wno-uninitialized") -set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -pthread -fvisibility=hidden -std=c++14 -fsigned-char") + -Wno-missing-field-initializers -Wno-uninitialized") +set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -pthread -fPIC -fvisibility=hidden -std=c++14 -fsigned-char") if (build_SYNC) set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ENABLE_SYNC=1") endif() @@ -199,9 +199,9 @@ add_library(realm-jni SHARED ${jni_SRC} ${objectstore_SRC} ${objectstore_sync_SR add_dependencies(realm-jni jni_headers) if (build_SYNC) - target_link_libraries(realm-jni log android lib_realm_sync crypto ssl) + target_link_libraries(realm-jni log android lib_realm_sync OpenSSL::SSL OpenSSL::Crypto) else() - target_link_libraries(realm-jni log android lib_realm_core crypto) + target_link_libraries(realm-jni log android lib_realm_core OpenSSL::Crypto) endif() # Strip the release so files and backup the unstripped versions diff --git a/realm/realm-library/src/main/cpp/android.toolchain.cmake b/realm/realm-library/src/main/cpp/android.toolchain.cmake deleted file mode 100644 index 86046dfa45..0000000000 --- a/realm/realm-library/src/main/cpp/android.toolchain.cmake +++ /dev/null @@ -1,1703 +0,0 @@ -# Copyright (c) 2010-2011, Ethan Rublee -# Copyright (c) 2011-2014, Andrey Kamaev -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, -# this list of conditions and the following disclaimer in the documentation -# and/or other materials provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its -# contributors may be used to endorse or promote products derived from this -# software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. - -# ------------------------------------------------------------------------------ -# Android CMake toolchain file, for use with the Android NDK r5-r10d -# Requires cmake 2.6.3 or newer (2.8.9 or newer is recommended). -# See home page: https://github.com/taka-no-me/android-cmake -# -# Usage Linux: -# $ export ANDROID_NDK=/absolute/path/to/the/android-ndk -# $ mkdir build && cd build -# $ cmake -DCMAKE_TOOLCHAIN_FILE=path/to/the/android.toolchain.cmake .. -# $ make -j8 -# -# Usage Windows: -# You need native port of make to build your project. -# Android NDK r7 (and newer) already has make.exe on board. -# For older NDK you have to install it separately. -# For example, this one: http://gnuwin32.sourceforge.net/packages/make.htm -# -# $ SET ANDROID_NDK=C:\absolute\path\to\the\android-ndk -# $ mkdir build && cd build -# $ cmake.exe -G"MinGW Makefiles" -# -DCMAKE_TOOLCHAIN_FILE=path\to\the\android.toolchain.cmake -# -DCMAKE_MAKE_PROGRAM="%ANDROID_NDK%\prebuilt\windows\bin\make.exe" .. -# $ cmake.exe --build . -# -# -# Options (can be set as cmake parameters: -D=): -# ANDROID_NDK=/opt/android-ndk - path to the NDK root. -# Can be set as environment variable. Can be set only at first cmake run. -# -# ANDROID_ABI=armeabi-v7a - specifies the target Application Binary -# Interface (ABI). This option nearly matches to the APP_ABI variable -# used by ndk-build tool from Android NDK. -# -# Possible targets are: -# "armeabi" - ARMv5TE based CPU with software floating point operations -# "armeabi-v7a" - ARMv7 based devices with hardware FPU instructions -# this ABI target is used by default -# "armeabi-v7a with NEON" - same as armeabi-v7a, but -# sets NEON as floating-point unit -# "armeabi-v7a with VFPV3" - same as armeabi-v7a, but -# sets VFPV3 as floating-point unit (has 32 registers instead of 16) -# "armeabi-v6 with VFP" - tuned for ARMv6 processors having VFP -# "x86" - IA-32 instruction set -# "mips" - MIPS32 instruction set -# -# 64-bit ABIs for NDK r10 and newer: -# "arm64-v8a" - ARMv8 AArch64 instruction set -# "x86_64" - Intel64 instruction set (r1) -# "mips64" - MIPS64 instruction set (r6) -# -# ANDROID_NATIVE_API_LEVEL=android-9 - level of Android API compile for. -# Option is read-only when standalone toolchain is used. -# Note: building for "android-L" requires explicit configuration. -# -# ANDROID_TOOLCHAIN_NAME=arm-linux-androideabi-4.9 - the name of compiler -# toolchain to be used. The list of possible values depends on the NDK -# version. For NDK r10c the possible values are: -# -# * aarch64-linux-android-4.9 -# * aarch64-linux-android-clang3.4 -# * aarch64-linux-android-clang3.5 -# * arm-linux-androideabi-4.6 -# * arm-linux-androideabi-4.8 -# * arm-linux-androideabi-4.9 (default) -# * arm-linux-androideabi-clang3.4 -# * arm-linux-androideabi-clang3.5 -# * mips64el-linux-android-4.9 -# * mips64el-linux-android-clang3.4 -# * mips64el-linux-android-clang3.5 -# * mipsel-linux-android-4.6 -# * mipsel-linux-android-4.8 -# * mipsel-linux-android-4.9 -# * mipsel-linux-android-clang3.4 -# * mipsel-linux-android-clang3.5 -# * x86-4.6 -# * x86-4.8 -# * x86-4.9 -# * x86-clang3.4 -# * x86-clang3.5 -# * x86_64-4.9 -# * x86_64-clang3.4 -# * x86_64-clang3.5 -# -# ANDROID_FORCE_ARM_BUILD=OFF - set ON to generate 32-bit ARM instructions -# instead of Thumb. Is not available for "armeabi-v6 with VFP" -# (is forced to be ON) ABI. -# -# ANDROID_NO_UNDEFINED=ON - set ON to show all undefined symbols as linker -# errors even if they are not used. -# -# ANDROID_SO_UNDEFINED=OFF - set ON to allow undefined symbols in shared -# libraries. Automatically turned for NDK r5x and r6x due to GLESv2 -# problems. -# -# ANDROID_STL=gnustl_static - specify the runtime to use. -# -# Possible values are: -# none -> Do not configure the runtime. -# system -> Use the default minimal system C++ runtime library. -# Implies -fno-rtti -fno-exceptions. -# Is not available for standalone toolchain. -# system_re -> Use the default minimal system C++ runtime library. -# Implies -frtti -fexceptions. -# Is not available for standalone toolchain. -# gabi++_static -> Use the GAbi++ runtime as a static library. -# Implies -frtti -fno-exceptions. -# Available for NDK r7 and newer. -# Is not available for standalone toolchain. -# gabi++_shared -> Use the GAbi++ runtime as a shared library. -# Implies -frtti -fno-exceptions. -# Available for NDK r7 and newer. -# Is not available for standalone toolchain. -# stlport_static -> Use the STLport runtime as a static library. -# Implies -fno-rtti -fno-exceptions for NDK before r7. -# Implies -frtti -fno-exceptions for NDK r7 and newer. -# Is not available for standalone toolchain. -# stlport_shared -> Use the STLport runtime as a shared library. -# Implies -fno-rtti -fno-exceptions for NDK before r7. -# Implies -frtti -fno-exceptions for NDK r7 and newer. -# Is not available for standalone toolchain. -# gnustl_static -> Use the GNU STL as a static library. -# Implies -frtti -fexceptions. -# gnustl_shared -> Use the GNU STL as a shared library. -# Implies -frtti -fno-exceptions. -# Available for NDK r7b and newer. -# Silently degrades to gnustl_static if not available. -# -# ANDROID_STL_FORCE_FEATURES=ON - turn rtti and exceptions support based on -# chosen runtime. If disabled, then the user is responsible for settings -# these options. -# -# What?: -# android-cmake toolchain searches for NDK/toolchain in the following order: -# ANDROID_NDK - cmake parameter -# ANDROID_NDK - environment variable -# ANDROID_STANDALONE_TOOLCHAIN - cmake parameter -# ANDROID_STANDALONE_TOOLCHAIN - environment variable -# ANDROID_NDK - default locations -# ANDROID_STANDALONE_TOOLCHAIN - default locations -# -# Make sure to do the following in your scripts: -# SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${my_cxx_flags}" ) -# SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${my_cxx_flags}" ) -# The flags will be prepopulated with critical flags, so don't loose them. -# Also be aware that toolchain also sets configuration-specific compiler -# flags and linker flags. -# -# ANDROID and BUILD_ANDROID will be set to true, you may test any of these -# variables to make necessary Android-specific configuration changes. -# -# Also ARMEABI or ARMEABI_V7A or X86 or MIPS or ARM64_V8A or X86_64 or MIPS64 -# will be set true, mutually exclusive. NEON option will be set true -# if VFP is set to NEON. -# -# ------------------------------------------------------------------------------ - -# FIXME: -# This is copied from https://dl.google.com/android/repository/cmake-3.4.2909474-linux-x86_64.zip -# because of the android.toolchain.cmake shipped with Android SDK CMake 3.6 doesn't work with our -# JNI build currently (lack of lto linking support.). Two modifications are made to avoid warnings -# with CMake 3.6 -- disable CMAKE_FORCE_CXX_COMPILER & CMAKE_FORCE_C_COMPILER. -# This file should be removed and use the one from Android SDK cmake package when it supports lto. - -cmake_minimum_required( VERSION 2.6.3 ) - -if( DEFINED CMAKE_CROSSCOMPILING ) - # subsequent toolchain loading is not really needed - return() -endif() - -if( CMAKE_TOOLCHAIN_FILE ) - # touch toolchain variable to suppress "unused variable" warning -endif() - -# inherit settings in recursive loads -get_property( _CMAKE_IN_TRY_COMPILE GLOBAL PROPERTY IN_TRY_COMPILE ) -if( _CMAKE_IN_TRY_COMPILE ) - include( "${CMAKE_CURRENT_SOURCE_DIR}/../android.toolchain.config.cmake" OPTIONAL ) -endif() - -# this one is important -if( CMAKE_VERSION VERSION_GREATER "3.0.99" ) - set( CMAKE_SYSTEM_NAME Android ) -else() - set( CMAKE_SYSTEM_NAME Linux ) -endif() - -# this one not so much -set( CMAKE_SYSTEM_VERSION 1 ) - -# rpath makes low sense for Android -set( CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "" ) -set( CMAKE_SKIP_RPATH TRUE CACHE BOOL "If set, runtime paths are not added when using shared libraries." ) - -# NDK search paths -set( ANDROID_SUPPORTED_NDK_VERSIONS ${ANDROID_EXTRA_NDK_VERSIONS} -r10d -r10c -r10b -r10 -r9d -r9c -r9b -r9 -r8e -r8d -r8c -r8b -r8 -r7c -r7b -r7 -r6b -r6 -r5c -r5b -r5 "" ) -if( NOT DEFINED ANDROID_NDK_SEARCH_PATHS ) - if( CMAKE_HOST_WIN32 ) - file( TO_CMAKE_PATH "$ENV{PROGRAMFILES}" ANDROID_NDK_SEARCH_PATHS ) - set( ANDROID_NDK_SEARCH_PATHS "${ANDROID_NDK_SEARCH_PATHS}" "$ENV{SystemDrive}/NVPACK" ) - else() - file( TO_CMAKE_PATH "$ENV{HOME}" ANDROID_NDK_SEARCH_PATHS ) - set( ANDROID_NDK_SEARCH_PATHS /opt "${ANDROID_NDK_SEARCH_PATHS}/NVPACK" ) - endif() -endif() -if( NOT DEFINED ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH ) - set( ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH /opt/android-toolchain ) -endif() - -# known ABIs -set( ANDROID_SUPPORTED_ABIS_arm "armeabi-v7a;armeabi;armeabi-v7a with NEON;armeabi-v7a with VFPV3;armeabi-v6 with VFP" ) -set( ANDROID_SUPPORTED_ABIS_arm64 "arm64-v8a" ) -set( ANDROID_SUPPORTED_ABIS_x86 "x86" ) -set( ANDROID_SUPPORTED_ABIS_x86_64 "x86_64" ) -set( ANDROID_SUPPORTED_ABIS_mips "mips" ) -set( ANDROID_SUPPORTED_ABIS_mips64 "mips64" ) - -# API level defaults -set( ANDROID_DEFAULT_NDK_API_LEVEL 9 ) -set( ANDROID_DEFAULT_NDK_API_LEVEL_arm64 21 ) -set( ANDROID_DEFAULT_NDK_API_LEVEL_x86 9 ) -set( ANDROID_DEFAULT_NDK_API_LEVEL_x86_64 21 ) -set( ANDROID_DEFAULT_NDK_API_LEVEL_mips 9 ) -set( ANDROID_DEFAULT_NDK_API_LEVEL_mips64 21 ) - - -macro( __LIST_FILTER listvar regex ) - if( ${listvar} ) - foreach( __val ${${listvar}} ) - if( __val MATCHES "${regex}" ) - list( REMOVE_ITEM ${listvar} "${__val}" ) - endif() - endforeach() - endif() -endmacro() - -macro( __INIT_VARIABLE var_name ) - set( __test_path 0 ) - foreach( __var ${ARGN} ) - if( __var STREQUAL "PATH" ) - set( __test_path 1 ) - break() - endif() - endforeach() - - if( __test_path AND NOT EXISTS "${${var_name}}" ) - unset( ${var_name} CACHE ) - endif() - - if( " ${${var_name}}" STREQUAL " " ) - set( __values 0 ) - foreach( __var ${ARGN} ) - if( __var STREQUAL "VALUES" ) - set( __values 1 ) - elseif( NOT __var STREQUAL "PATH" ) - if( __var MATCHES "^ENV_.*$" ) - string( REPLACE "ENV_" "" __var "${__var}" ) - set( __value "$ENV{${__var}}" ) - elseif( DEFINED ${__var} ) - set( __value "${${__var}}" ) - elseif( __values ) - set( __value "${__var}" ) - else() - set( __value "" ) - endif() - - if( NOT " ${__value}" STREQUAL " " AND (NOT __test_path OR EXISTS "${__value}") ) - set( ${var_name} "${__value}" ) - break() - endif() - endif() - endforeach() - unset( __value ) - unset( __values ) - endif() - - if( __test_path ) - file( TO_CMAKE_PATH "${${var_name}}" ${var_name} ) - endif() - unset( __test_path ) -endmacro() - -macro( __DETECT_NATIVE_API_LEVEL _var _path ) - set( __ndkApiLevelRegex "^[\t ]*#define[\t ]+__ANDROID_API__[\t ]+([0-9]+)[\t ]*.*$" ) - file( STRINGS ${_path} __apiFileContent REGEX "${__ndkApiLevelRegex}" ) - if( NOT __apiFileContent ) - message( SEND_ERROR "Could not get Android native API level. Probably you have specified invalid level value, or your copy of NDK/toolchain is broken." ) - endif() - string( REGEX REPLACE "${__ndkApiLevelRegex}" "\\1" ${_var} "${__apiFileContent}" ) - unset( __apiFileContent ) - unset( __ndkApiLevelRegex ) -endmacro() - -macro( __DETECT_TOOLCHAIN_MACHINE_NAME _var _root ) - if( EXISTS "${_root}" ) - file( GLOB __gccExePath RELATIVE "${_root}/bin/" "${_root}/bin/*-gcc${TOOL_OS_SUFFIX}" ) - __LIST_FILTER( __gccExePath "^[.].*" ) - list( LENGTH __gccExePath __gccExePathsCount ) - if( NOT __gccExePathsCount EQUAL 1 AND NOT _CMAKE_IN_TRY_COMPILE ) - message( WARNING "Could not determine machine name for compiler from ${_root}" ) - set( ${_var} "" ) - else() - get_filename_component( __gccExeName "${__gccExePath}" NAME_WE ) - string( REPLACE "-gcc" "" ${_var} "${__gccExeName}" ) - endif() - unset( __gccExePath ) - unset( __gccExePathsCount ) - unset( __gccExeName ) - else() - set( ${_var} "" ) - endif() -endmacro() - - -# fight against cygwin -set( ANDROID_FORBID_SYGWIN TRUE CACHE BOOL "Prevent cmake from working under cygwin and using cygwin tools") -mark_as_advanced( ANDROID_FORBID_SYGWIN ) -if( ANDROID_FORBID_SYGWIN ) - if( CYGWIN ) - message( FATAL_ERROR "Android NDK and android-cmake toolchain are not welcome Cygwin. It is unlikely that this cmake toolchain will work under cygwin. But if you want to try then you can set cmake variable ANDROID_FORBID_SYGWIN to FALSE and rerun cmake." ) - endif() - - if( CMAKE_HOST_WIN32 ) - # remove cygwin from PATH - set( __new_path "$ENV{PATH}") - __LIST_FILTER( __new_path "cygwin" ) - set(ENV{PATH} "${__new_path}") - unset(__new_path) - endif() -endif() - - -# detect current host platform -if( NOT DEFINED ANDROID_NDK_HOST_X64 AND (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|AMD64" OR CMAKE_HOST_APPLE) ) - set( ANDROID_NDK_HOST_X64 1 CACHE BOOL "Try to use 64-bit compiler toolchain" ) - mark_as_advanced( ANDROID_NDK_HOST_X64 ) -endif() - -set( TOOL_OS_SUFFIX "" ) -if( CMAKE_HOST_APPLE ) - set( ANDROID_NDK_HOST_SYSTEM_NAME "darwin-x86_64" ) - set( ANDROID_NDK_HOST_SYSTEM_NAME2 "darwin-x86" ) -elseif( CMAKE_HOST_WIN32 ) - set( ANDROID_NDK_HOST_SYSTEM_NAME "windows-x86_64" ) - set( ANDROID_NDK_HOST_SYSTEM_NAME2 "windows" ) - set( TOOL_OS_SUFFIX ".exe" ) -elseif( CMAKE_HOST_UNIX ) - set( ANDROID_NDK_HOST_SYSTEM_NAME "linux-x86_64" ) - set( ANDROID_NDK_HOST_SYSTEM_NAME2 "linux-x86" ) -else() - message( FATAL_ERROR "Cross-compilation on your platform is not supported by this cmake toolchain" ) -endif() - -if( NOT ANDROID_NDK_HOST_X64 ) - set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) -endif() - -# see if we have path to Android NDK -if( NOT ANDROID_NDK AND NOT ANDROID_STANDALONE_TOOLCHAIN ) - __INIT_VARIABLE( ANDROID_NDK PATH ENV_ANDROID_NDK ) -endif() -if( NOT ANDROID_NDK ) - # see if we have path to Android standalone toolchain - __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ENV_ANDROID_STANDALONE_TOOLCHAIN ) - - if( NOT ANDROID_STANDALONE_TOOLCHAIN ) - #try to find Android NDK in one of the the default locations - set( __ndkSearchPaths ) - foreach( __ndkSearchPath ${ANDROID_NDK_SEARCH_PATHS} ) - foreach( suffix ${ANDROID_SUPPORTED_NDK_VERSIONS} ) - list( APPEND __ndkSearchPaths "${__ndkSearchPath}/android-ndk${suffix}" ) - endforeach() - endforeach() - __INIT_VARIABLE( ANDROID_NDK PATH VALUES ${__ndkSearchPaths} ) - unset( __ndkSearchPaths ) - - if( ANDROID_NDK ) - message( STATUS "Using default path for Android NDK: ${ANDROID_NDK}" ) - message( STATUS " If you prefer to use a different location, please define a cmake or environment variable: ANDROID_NDK" ) - else() - #try to find Android standalone toolchain in one of the the default locations - __INIT_VARIABLE( ANDROID_STANDALONE_TOOLCHAIN PATH ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH ) - - if( ANDROID_STANDALONE_TOOLCHAIN ) - message( STATUS "Using default path for standalone toolchain ${ANDROID_STANDALONE_TOOLCHAIN}" ) - message( STATUS " If you prefer to use a different location, please define the variable: ANDROID_STANDALONE_TOOLCHAIN" ) - endif( ANDROID_STANDALONE_TOOLCHAIN ) - endif( ANDROID_NDK ) - endif( NOT ANDROID_STANDALONE_TOOLCHAIN ) -endif( NOT ANDROID_NDK ) - -# remember found paths -if( ANDROID_NDK ) - get_filename_component( ANDROID_NDK "${ANDROID_NDK}" ABSOLUTE ) - set( ANDROID_NDK "${ANDROID_NDK}" CACHE INTERNAL "Path of the Android NDK" FORCE ) - set( BUILD_WITH_ANDROID_NDK True ) - if( EXISTS "${ANDROID_NDK}/RELEASE.TXT" ) - file( STRINGS "${ANDROID_NDK}/RELEASE.TXT" ANDROID_NDK_RELEASE_FULL LIMIT_COUNT 1 REGEX "r[0-9]+[a-z]?" ) - string( REGEX MATCH "r([0-9]+)([a-z]?)" ANDROID_NDK_RELEASE "${ANDROID_NDK_RELEASE_FULL}" ) - else() - set( ANDROID_NDK_RELEASE "r1x" ) - set( ANDROID_NDK_RELEASE_FULL "unreleased" ) - endif() - string( REGEX REPLACE "r([0-9]+)([a-z]?)" "\\1*1000" ANDROID_NDK_RELEASE_NUM "${ANDROID_NDK_RELEASE}" ) - string( FIND " abcdefghijklmnopqastuvwxyz" "${CMAKE_MATCH_2}" __ndkReleaseLetterNum ) - math( EXPR ANDROID_NDK_RELEASE_NUM "${ANDROID_NDK_RELEASE_NUM}+${__ndkReleaseLetterNum}" ) -elseif( ANDROID_STANDALONE_TOOLCHAIN ) - get_filename_component( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" ABSOLUTE ) - # try to detect change - if( CMAKE_AR ) - string( LENGTH "${ANDROID_STANDALONE_TOOLCHAIN}" __length ) - string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidStandaloneToolchainPreviousPath ) - if( NOT __androidStandaloneToolchainPreviousPath STREQUAL ANDROID_STANDALONE_TOOLCHAIN ) - message( FATAL_ERROR "It is not possible to change path to the Android standalone toolchain on subsequent run." ) - endif() - unset( __androidStandaloneToolchainPreviousPath ) - unset( __length ) - endif() - set( ANDROID_STANDALONE_TOOLCHAIN "${ANDROID_STANDALONE_TOOLCHAIN}" CACHE INTERNAL "Path of the Android standalone toolchain" FORCE ) - set( BUILD_WITH_STANDALONE_TOOLCHAIN True ) -else() - list(GET ANDROID_NDK_SEARCH_PATHS 0 ANDROID_NDK_SEARCH_PATH) - message( FATAL_ERROR "Could not find neither Android NDK nor Android standalone toolchain. - You should either set an environment variable: - export ANDROID_NDK=~/my-android-ndk - or - export ANDROID_STANDALONE_TOOLCHAIN=~/my-android-toolchain - or put the toolchain or NDK in the default path: - sudo ln -s ~/my-android-ndk ${ANDROID_NDK_SEARCH_PATH}/android-ndk - sudo ln -s ~/my-android-toolchain ${ANDROID_STANDALONE_TOOLCHAIN_SEARCH_PATH}" ) -endif() - -# android NDK layout -if( BUILD_WITH_ANDROID_NDK ) - if( NOT DEFINED ANDROID_NDK_LAYOUT ) - # try to automatically detect the layout - if( EXISTS "${ANDROID_NDK}/RELEASE.TXT") - set( ANDROID_NDK_LAYOUT "RELEASE" ) - elseif( EXISTS "${ANDROID_NDK}/../../linux-x86/toolchain/" ) - set( ANDROID_NDK_LAYOUT "LINARO" ) - elseif( EXISTS "${ANDROID_NDK}/../../gcc/" ) - set( ANDROID_NDK_LAYOUT "ANDROID" ) - endif() - endif() - set( ANDROID_NDK_LAYOUT "${ANDROID_NDK_LAYOUT}" CACHE STRING "The inner layout of NDK" ) - mark_as_advanced( ANDROID_NDK_LAYOUT ) - if( ANDROID_NDK_LAYOUT STREQUAL "LINARO" ) - set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) # only 32-bit at the moment - set( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/../../${ANDROID_NDK_HOST_SYSTEM_NAME}/toolchain" ) - set( ANDROID_NDK_TOOLCHAINS_SUBPATH "" ) - set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "" ) - elseif( ANDROID_NDK_LAYOUT STREQUAL "ANDROID" ) - set( ANDROID_NDK_HOST_SYSTEM_NAME ${ANDROID_NDK_HOST_SYSTEM_NAME2} ) # only 32-bit at the moment - set( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/../../gcc/${ANDROID_NDK_HOST_SYSTEM_NAME}/arm" ) - set( ANDROID_NDK_TOOLCHAINS_SUBPATH "" ) - set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "" ) - else() # ANDROID_NDK_LAYOUT STREQUAL "RELEASE" - set( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK}/toolchains" ) - set( ANDROID_NDK_TOOLCHAINS_SUBPATH "/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME}" ) - set( ANDROID_NDK_TOOLCHAINS_SUBPATH2 "/prebuilt/${ANDROID_NDK_HOST_SYSTEM_NAME2}" ) - endif() - get_filename_component( ANDROID_NDK_TOOLCHAINS_PATH "${ANDROID_NDK_TOOLCHAINS_PATH}" ABSOLUTE ) - - # try to detect change of NDK - if( CMAKE_AR ) - string( LENGTH "${ANDROID_NDK_TOOLCHAINS_PATH}" __length ) - string( SUBSTRING "${CMAKE_AR}" 0 ${__length} __androidNdkPreviousPath ) - if( NOT __androidNdkPreviousPath STREQUAL ANDROID_NDK_TOOLCHAINS_PATH ) - message( FATAL_ERROR "It is not possible to change the path to the NDK on subsequent CMake run. You must remove all generated files from your build folder first. - " ) - endif() - unset( __androidNdkPreviousPath ) - unset( __length ) - endif() -endif() - - -# get all the details about standalone toolchain -if( BUILD_WITH_STANDALONE_TOOLCHAIN ) - __DETECT_NATIVE_API_LEVEL( ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot/usr/include/android/api-level.h" ) - set( ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) - set( __availableToolchains "standalone" ) - __DETECT_TOOLCHAIN_MACHINE_NAME( __availableToolchainMachines "${ANDROID_STANDALONE_TOOLCHAIN}" ) - if( NOT __availableToolchainMachines ) - message( FATAL_ERROR "Could not determine machine name of your toolchain. Probably your Android standalone toolchain is broken." ) - endif() - if( __availableToolchainMachines MATCHES x86_64 ) - set( __availableToolchainArchs "x86_64" ) - elseif( __availableToolchainMachines MATCHES i686 ) - set( __availableToolchainArchs "x86" ) - elseif( __availableToolchainMachines MATCHES aarch64 ) - set( __availableToolchainArchs "arm64" ) - elseif( __availableToolchainMachines MATCHES arm ) - set( __availableToolchainArchs "arm" ) - elseif( __availableToolchainMachines MATCHES mips64el ) - set( __availableToolchainArchs "mips64" ) - elseif( __availableToolchainMachines MATCHES mipsel ) - set( __availableToolchainArchs "mips" ) - endif() - execute_process( COMMAND "${ANDROID_STANDALONE_TOOLCHAIN}/bin/${__availableToolchainMachines}-gcc${TOOL_OS_SUFFIX}" -dumpversion - OUTPUT_VARIABLE __availableToolchainCompilerVersions OUTPUT_STRIP_TRAILING_WHITESPACE ) - string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9]+)?" __availableToolchainCompilerVersions "${__availableToolchainCompilerVersions}" ) - if( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/bin/clang${TOOL_OS_SUFFIX}" ) - list( APPEND __availableToolchains "standalone-clang" ) - list( APPEND __availableToolchainMachines ${__availableToolchainMachines} ) - list( APPEND __availableToolchainArchs ${__availableToolchainArchs} ) - list( APPEND __availableToolchainCompilerVersions ${__availableToolchainCompilerVersions} ) - endif() -endif() - -macro( __GLOB_NDK_TOOLCHAINS __availableToolchainsVar __availableToolchainsLst __toolchain_subpath ) - foreach( __toolchain ${${__availableToolchainsLst}} ) - if( "${__toolchain}" MATCHES "-clang3[.][0-9]$" AND NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}${__toolchain_subpath}" ) - SET( __toolchainVersionRegex "^TOOLCHAIN_VERSION[\t ]+:=[\t ]+(.*)$" ) - FILE( STRINGS "${ANDROID_NDK_TOOLCHAINS_PATH}/${__toolchain}/setup.mk" __toolchainVersionStr REGEX "${__toolchainVersionRegex}" ) - if( __toolchainVersionStr ) - string( REGEX REPLACE "${__toolchainVersionRegex}" "\\1" __toolchainVersionStr "${__toolchainVersionStr}" ) - string( REGEX REPLACE "-clang3[.][0-9]$" "-${__toolchainVersionStr}" __gcc_toolchain "${__toolchain}" ) - else() - string( REGEX REPLACE "-clang3[.][0-9]$" "-4.6" __gcc_toolchain "${__toolchain}" ) - endif() - unset( __toolchainVersionStr ) - unset( __toolchainVersionRegex ) - else() - set( __gcc_toolchain "${__toolchain}" ) - endif() - __DETECT_TOOLCHAIN_MACHINE_NAME( __machine "${ANDROID_NDK_TOOLCHAINS_PATH}/${__gcc_toolchain}${__toolchain_subpath}" ) - if( __machine ) - string( REGEX MATCH "[0-9]+[.][0-9]+([.][0-9x]+)?$" __version "${__gcc_toolchain}" ) - if( __machine MATCHES x86_64 ) - set( __arch "x86_64" ) - elseif( __machine MATCHES i686 ) - set( __arch "x86" ) - elseif( __machine MATCHES aarch64 ) - set( __arch "arm64" ) - elseif( __machine MATCHES arm ) - set( __arch "arm" ) - elseif( __machine MATCHES mips64el ) - set( __arch "mips64" ) - elseif( __machine MATCHES mipsel ) - set( __arch "mips" ) - else() - set( __arch "" ) - endif() - #message("machine: !${__machine}!\narch: !${__arch}!\nversion: !${__version}!\ntoolchain: !${__toolchain}!\n") - if (__arch) - list( APPEND __availableToolchainMachines "${__machine}" ) - list( APPEND __availableToolchainArchs "${__arch}" ) - list( APPEND __availableToolchainCompilerVersions "${__version}" ) - list( APPEND ${__availableToolchainsVar} "${__toolchain}" ) - endif() - endif() - unset( __gcc_toolchain ) - endforeach() -endmacro() - -# get all the details about NDK -if( BUILD_WITH_ANDROID_NDK ) - file( GLOB ANDROID_SUPPORTED_NATIVE_API_LEVELS RELATIVE "${ANDROID_NDK}/platforms" "${ANDROID_NDK}/platforms/android-*" ) - string( REPLACE "android-" "" ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_SUPPORTED_NATIVE_API_LEVELS}" ) - set( __availableToolchains "" ) - set( __availableToolchainMachines "" ) - set( __availableToolchainArchs "" ) - set( __availableToolchainCompilerVersions "" ) - if( ANDROID_TOOLCHAIN_NAME AND EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_TOOLCHAIN_NAME}/" ) - # do not go through all toolchains if we know the name - set( __availableToolchainsLst "${ANDROID_TOOLCHAIN_NAME}" ) - __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) - if( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 ) - __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH2}" ) - if( __availableToolchains ) - set( ANDROID_NDK_TOOLCHAINS_SUBPATH ${ANDROID_NDK_TOOLCHAINS_SUBPATH2} ) - endif() - endif() - endif() - if( NOT __availableToolchains ) - file( GLOB __availableToolchainsLst RELATIVE "${ANDROID_NDK_TOOLCHAINS_PATH}" "${ANDROID_NDK_TOOLCHAINS_PATH}/*" ) - if( __availableToolchainsLst ) - list(SORT __availableToolchainsLst) # we need clang to go after gcc - endif() - __LIST_FILTER( __availableToolchainsLst "^[.]" ) - __LIST_FILTER( __availableToolchainsLst "llvm" ) - __LIST_FILTER( __availableToolchainsLst "renderscript" ) - __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) - if( NOT __availableToolchains AND NOT ANDROID_NDK_TOOLCHAINS_SUBPATH STREQUAL ANDROID_NDK_TOOLCHAINS_SUBPATH2 ) - __GLOB_NDK_TOOLCHAINS( __availableToolchains __availableToolchainsLst "${ANDROID_NDK_TOOLCHAINS_SUBPATH2}" ) - if( __availableToolchains ) - set( ANDROID_NDK_TOOLCHAINS_SUBPATH ${ANDROID_NDK_TOOLCHAINS_SUBPATH2} ) - endif() - endif() - endif() - if( NOT __availableToolchains ) - message( FATAL_ERROR "Could not find any working toolchain in the NDK. Probably your Android NDK is broken." ) - endif() -endif() - -# build list of available ABIs -set( ANDROID_SUPPORTED_ABIS "" ) -set( __uniqToolchainArchNames ${__availableToolchainArchs} ) -list( REMOVE_DUPLICATES __uniqToolchainArchNames ) -list( SORT __uniqToolchainArchNames ) -foreach( __arch ${__uniqToolchainArchNames} ) - list( APPEND ANDROID_SUPPORTED_ABIS ${ANDROID_SUPPORTED_ABIS_${__arch}} ) -endforeach() -unset( __uniqToolchainArchNames ) -if( NOT ANDROID_SUPPORTED_ABIS ) - message( FATAL_ERROR "No one of known Android ABIs is supported by this cmake toolchain." ) -endif() - -# choose target ABI -__INIT_VARIABLE( ANDROID_ABI VALUES ${ANDROID_SUPPORTED_ABIS} ) -# verify that target ABI is supported -list( FIND ANDROID_SUPPORTED_ABIS "${ANDROID_ABI}" __androidAbiIdx ) -if( __androidAbiIdx EQUAL -1 ) - string( REPLACE ";" "\", \"" PRINTABLE_ANDROID_SUPPORTED_ABIS "${ANDROID_SUPPORTED_ABIS}" ) - message( FATAL_ERROR "Specified ANDROID_ABI = \"${ANDROID_ABI}\" is not supported by this cmake toolchain or your NDK/toolchain. - Supported values are: \"${PRINTABLE_ANDROID_SUPPORTED_ABIS}\" - " ) -endif() -unset( __androidAbiIdx ) - -# set target ABI options -if( ANDROID_ABI STREQUAL "x86" ) - set( X86 true ) - set( ANDROID_NDK_ABI_NAME "x86" ) - set( ANDROID_ARCH_NAME "x86" ) - set( ANDROID_LLVM_TRIPLE "i686-none-linux-android" ) - set( CMAKE_SYSTEM_PROCESSOR "i686" ) -elseif( ANDROID_ABI STREQUAL "x86_64" ) - set( X86 true ) - set( X86_64 true ) - set( ANDROID_NDK_ABI_NAME "x86_64" ) - set( ANDROID_ARCH_NAME "x86_64" ) - set( CMAKE_SYSTEM_PROCESSOR "x86_64" ) - set( ANDROID_LLVM_TRIPLE "x86_64-none-linux-android" ) -elseif( ANDROID_ABI STREQUAL "mips64" ) - set( MIPS64 true ) - set( ANDROID_NDK_ABI_NAME "mips64" ) - set( ANDROID_ARCH_NAME "mips64" ) - set( ANDROID_LLVM_TRIPLE "mips64el-none-linux-android" ) - set( CMAKE_SYSTEM_PROCESSOR "mips64" ) -elseif( ANDROID_ABI STREQUAL "mips" ) - set( MIPS true ) - set( ANDROID_NDK_ABI_NAME "mips" ) - set( ANDROID_ARCH_NAME "mips" ) - set( ANDROID_LLVM_TRIPLE "mipsel-none-linux-android" ) - set( CMAKE_SYSTEM_PROCESSOR "mips" ) -elseif( ANDROID_ABI STREQUAL "arm64-v8a" ) - set( ARM64_V8A true ) - set( ANDROID_NDK_ABI_NAME "arm64-v8a" ) - set( ANDROID_ARCH_NAME "arm64" ) - set( ANDROID_LLVM_TRIPLE "aarch64-none-linux-android" ) - set( CMAKE_SYSTEM_PROCESSOR "aarch64" ) - set( VFPV3 true ) - set( NEON true ) -elseif( ANDROID_ABI STREQUAL "armeabi" ) - set( ARMEABI true ) - set( ANDROID_NDK_ABI_NAME "armeabi" ) - set( ANDROID_ARCH_NAME "arm" ) - set( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" ) - set( CMAKE_SYSTEM_PROCESSOR "armv5te" ) -elseif( ANDROID_ABI STREQUAL "armeabi-v6 with VFP" ) - set( ARMEABI_V6 true ) - set( ANDROID_NDK_ABI_NAME "armeabi" ) - set( ANDROID_ARCH_NAME "arm" ) - set( ANDROID_LLVM_TRIPLE "armv5te-none-linux-androideabi" ) - set( CMAKE_SYSTEM_PROCESSOR "armv6" ) - # need always fallback to older platform - set( ARMEABI true ) -elseif( ANDROID_ABI STREQUAL "armeabi-v7a") - set( ARMEABI_V7A true ) - set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) - set( ANDROID_ARCH_NAME "arm" ) - set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) - set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) -elseif( ANDROID_ABI STREQUAL "armeabi-v7a with VFPV3" ) - set( ARMEABI_V7A true ) - set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) - set( ANDROID_ARCH_NAME "arm" ) - set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) - set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) - set( VFPV3 true ) -elseif( ANDROID_ABI STREQUAL "armeabi-v7a with NEON" ) - set( ARMEABI_V7A true ) - set( ANDROID_NDK_ABI_NAME "armeabi-v7a" ) - set( ANDROID_ARCH_NAME "arm" ) - set( ANDROID_LLVM_TRIPLE "armv7-none-linux-androideabi" ) - set( CMAKE_SYSTEM_PROCESSOR "armv7-a" ) - set( VFPV3 true ) - set( NEON true ) -else() - message( SEND_ERROR "Unknown ANDROID_ABI=\"${ANDROID_ABI}\" is specified." ) -endif() - -if( CMAKE_BINARY_DIR AND EXISTS "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" ) - # really dirty hack - # it is not possible to change CMAKE_SYSTEM_PROCESSOR after the first run... - file( APPEND "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeSystem.cmake" "SET(CMAKE_SYSTEM_PROCESSOR \"${CMAKE_SYSTEM_PROCESSOR}\")\n" ) -endif() - -if( ANDROID_ARCH_NAME STREQUAL "arm" AND NOT ARMEABI_V6 ) - __INIT_VARIABLE( ANDROID_FORCE_ARM_BUILD VALUES OFF ) - set( ANDROID_FORCE_ARM_BUILD ${ANDROID_FORCE_ARM_BUILD} CACHE BOOL "Use 32-bit ARM instructions instead of Thumb-1" FORCE ) - mark_as_advanced( ANDROID_FORCE_ARM_BUILD ) -else() - unset( ANDROID_FORCE_ARM_BUILD CACHE ) -endif() - -# choose toolchain -if( ANDROID_TOOLCHAIN_NAME ) - list( FIND __availableToolchains "${ANDROID_TOOLCHAIN_NAME}" __toolchainIdx ) - if( __toolchainIdx EQUAL -1 ) - list( SORT __availableToolchains ) - string( REPLACE ";" "\n * " toolchains_list "${__availableToolchains}" ) - set( toolchains_list " * ${toolchains_list}") - message( FATAL_ERROR "Specified toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is missing in your NDK or broken. Please verify that your NDK is working or select another compiler toolchain. -To configure the toolchain set CMake variable ANDROID_TOOLCHAIN_NAME to one of the following values:\n${toolchains_list}\n" ) - endif() - list( GET __availableToolchainArchs ${__toolchainIdx} __toolchainArch ) - if( NOT __toolchainArch STREQUAL ANDROID_ARCH_NAME ) - message( SEND_ERROR "Selected toolchain \"${ANDROID_TOOLCHAIN_NAME}\" is not able to compile binaries for the \"${ANDROID_ARCH_NAME}\" platform." ) - endif() -else() - set( __toolchainIdx -1 ) - set( __applicableToolchains "" ) - set( __toolchainMaxVersion "0.0.0" ) - list( LENGTH __availableToolchains __availableToolchainsCount ) - math( EXPR __availableToolchainsCount "${__availableToolchainsCount}-1" ) - foreach( __idx RANGE ${__availableToolchainsCount} ) - list( GET __availableToolchainArchs ${__idx} __toolchainArch ) - if( __toolchainArch STREQUAL ANDROID_ARCH_NAME ) - list( GET __availableToolchainCompilerVersions ${__idx} __toolchainVersion ) - string( REPLACE "x" "99" __toolchainVersion "${__toolchainVersion}") - if( __toolchainVersion VERSION_GREATER __toolchainMaxVersion ) - set( __toolchainMaxVersion "${__toolchainVersion}" ) - set( __toolchainIdx ${__idx} ) - endif() - endif() - endforeach() - unset( __availableToolchainsCount ) - unset( __toolchainMaxVersion ) - unset( __toolchainVersion ) -endif() -unset( __toolchainArch ) -if( __toolchainIdx EQUAL -1 ) - message( FATAL_ERROR "No one of available compiler toolchains is able to compile for ${ANDROID_ARCH_NAME} platform." ) -endif() -list( GET __availableToolchains ${__toolchainIdx} ANDROID_TOOLCHAIN_NAME ) -list( GET __availableToolchainMachines ${__toolchainIdx} ANDROID_TOOLCHAIN_MACHINE_NAME ) -list( GET __availableToolchainCompilerVersions ${__toolchainIdx} ANDROID_COMPILER_VERSION ) - -unset( __toolchainIdx ) -unset( __availableToolchains ) -unset( __availableToolchainMachines ) -unset( __availableToolchainArchs ) -unset( __availableToolchainCompilerVersions ) - -# choose native API level -__INIT_VARIABLE( ANDROID_NATIVE_API_LEVEL ENV_ANDROID_NATIVE_API_LEVEL ANDROID_API_LEVEL ENV_ANDROID_API_LEVEL ANDROID_STANDALONE_TOOLCHAIN_API_LEVEL ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME} ANDROID_DEFAULT_NDK_API_LEVEL ) -string( REPLACE "android-" "" ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" ) -string( STRIP "${ANDROID_NATIVE_API_LEVEL}" ANDROID_NATIVE_API_LEVEL ) -# adjust API level -set( __real_api_level ${ANDROID_DEFAULT_NDK_API_LEVEL_${ANDROID_ARCH_NAME}} ) -foreach( __level ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) - if( (__level LESS ANDROID_NATIVE_API_LEVEL OR __level STREQUAL ANDROID_NATIVE_API_LEVEL) AND NOT __level LESS __real_api_level ) - set( __real_api_level ${__level} ) - endif() -endforeach() -if( __real_api_level AND NOT ANDROID_NATIVE_API_LEVEL STREQUAL __real_api_level ) - message( STATUS "Adjusting Android API level 'android-${ANDROID_NATIVE_API_LEVEL}' to 'android-${__real_api_level}'") - set( ANDROID_NATIVE_API_LEVEL ${__real_api_level} ) -endif() -unset(__real_api_level) -# validate -list( FIND ANDROID_SUPPORTED_NATIVE_API_LEVELS "${ANDROID_NATIVE_API_LEVEL}" __levelIdx ) -if( __levelIdx EQUAL -1 ) - message( SEND_ERROR "Specified Android native API level 'android-${ANDROID_NATIVE_API_LEVEL}' is not supported by your NDK/toolchain." ) -else() - if( BUILD_WITH_ANDROID_NDK ) - __DETECT_NATIVE_API_LEVEL( __realApiLevel "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}/usr/include/android/api-level.h" ) - if( NOT __realApiLevel EQUAL ANDROID_NATIVE_API_LEVEL AND NOT __realApiLevel GREATER 9000 ) - message( SEND_ERROR "Specified Android API level (${ANDROID_NATIVE_API_LEVEL}) does not match to the level found (${__realApiLevel}). Probably your copy of NDK is broken." ) - endif() - unset( __realApiLevel ) - endif() - set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE ) - set( CMAKE_ANDROID_API ${ANDROID_NATIVE_API_LEVEL} ) - if( CMAKE_VERSION VERSION_GREATER "2.8" ) - list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS ) - set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) - endif() -endif() -unset( __levelIdx ) - - -# remember target ABI -set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE ) -if( CMAKE_VERSION VERSION_GREATER "2.8" ) - list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME} ) - set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME}} ) -endif() - - -# runtime choice (STL, rtti, exceptions) -if( NOT ANDROID_STL ) - set( ANDROID_STL gnustl_static ) -endif() -set( ANDROID_STL "${ANDROID_STL}" CACHE STRING "C++ runtime" ) -set( ANDROID_STL_FORCE_FEATURES ON CACHE BOOL "automatically configure rtti and exceptions support based on C++ runtime" ) -mark_as_advanced( ANDROID_STL ANDROID_STL_FORCE_FEATURES ) - -if( BUILD_WITH_ANDROID_NDK ) - if( NOT "${ANDROID_STL}" MATCHES "^(none|system|system_re|gabi\\+\\+_static|gabi\\+\\+_shared|stlport_static|stlport_shared|gnustl_static|gnustl_shared)$") - message( FATAL_ERROR "ANDROID_STL is set to invalid value \"${ANDROID_STL}\". -The possible values are: - none -> Do not configure the runtime. - system -> Use the default minimal system C++ runtime library. - system_re -> Same as system but with rtti and exceptions. - gabi++_static -> Use the GAbi++ runtime as a static library. - gabi++_shared -> Use the GAbi++ runtime as a shared library. - stlport_static -> Use the STLport runtime as a static library. - stlport_shared -> Use the STLport runtime as a shared library. - gnustl_static -> (default) Use the GNU STL as a static library. - gnustl_shared -> Use the GNU STL as a shared library. -" ) - endif() -elseif( BUILD_WITH_STANDALONE_TOOLCHAIN ) - if( NOT "${ANDROID_STL}" MATCHES "^(none|gnustl_static|gnustl_shared)$") - message( FATAL_ERROR "ANDROID_STL is set to invalid value \"${ANDROID_STL}\". -The possible values are: - none -> Do not configure the runtime. - gnustl_static -> (default) Use the GNU STL as a static library. - gnustl_shared -> Use the GNU STL as a shared library. -" ) - endif() -endif() - -unset( ANDROID_RTTI ) -unset( ANDROID_EXCEPTIONS ) -unset( ANDROID_STL_INCLUDE_DIRS ) -unset( __libstl ) -unset( __libsupcxx ) - -if( NOT _CMAKE_IN_TRY_COMPILE AND ANDROID_NDK_RELEASE STREQUAL "r7b" AND ARMEABI_V7A AND NOT VFPV3 AND ANDROID_STL MATCHES "gnustl" ) - message( WARNING "The GNU STL armeabi-v7a binaries from NDK r7b can crash non-NEON devices. The files provided with NDK r7b were not configured properly, resulting in crashes on Tegra2-based devices and others when trying to use certain floating-point functions (e.g., cosf, sinf, expf). -You are strongly recommended to switch to another NDK release. -" ) -endif() - -if( NOT _CMAKE_IN_TRY_COMPILE AND X86 AND ANDROID_STL MATCHES "gnustl" AND ANDROID_NDK_RELEASE STREQUAL "r6" ) - message( WARNING "The x86 system header file from NDK r6 has incorrect definition for ptrdiff_t. You are recommended to upgrade to a newer NDK release or manually patch the header: -See https://android.googlesource.com/platform/development.git f907f4f9d4e56ccc8093df6fee54454b8bcab6c2 - diff --git a/ndk/platforms/android-9/arch-x86/include/machine/_types.h b/ndk/platforms/android-9/arch-x86/include/machine/_types.h - index 5e28c64..65892a1 100644 - --- a/ndk/platforms/android-9/arch-x86/include/machine/_types.h - +++ b/ndk/platforms/android-9/arch-x86/include/machine/_types.h - @@ -51,7 +51,11 @@ typedef long int ssize_t; - #endif - #ifndef _PTRDIFF_T - #define _PTRDIFF_T - -typedef long ptrdiff_t; - +# ifdef __ANDROID__ - + typedef int ptrdiff_t; - +# else - + typedef long ptrdiff_t; - +# endif - #endif -" ) -endif() - - -# setup paths and STL for standalone toolchain -if( BUILD_WITH_STANDALONE_TOOLCHAIN ) - set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) - set( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_STANDALONE_TOOLCHAIN}" ) - set( ANDROID_SYSROOT "${ANDROID_STANDALONE_TOOLCHAIN}/sysroot" ) - - if( NOT ANDROID_STL STREQUAL "none" ) - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/include/c++/${ANDROID_COMPILER_VERSION}" ) - if( NOT EXISTS "${ANDROID_STL_INCLUDE_DIRS}" ) - # old location ( pre r8c ) - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/include/c++/${ANDROID_COMPILER_VERSION}" ) - endif() - if( ARMEABI_V7A AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}/bits" ) - list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/${CMAKE_SYSTEM_PROCESSOR}" ) - elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb/bits" ) - list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/thumb" ) - else() - list( APPEND ANDROID_STL_INCLUDE_DIRS "${ANDROID_STL_INCLUDE_DIRS}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" ) - endif() - # always search static GNU STL to get the location of libsupc++.a - if( ARMEABI_V7A AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libstdc++.a" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb" ) - elseif( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libstdc++.a" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}" ) - elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libstdc++.a" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb" ) - elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libstdc++.a" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib" ) - endif() - if( __libstl ) - set( __libsupcxx "${__libstl}/libsupc++.a" ) - set( __libstl "${__libstl}/libstdc++.a" ) - endif() - if( NOT EXISTS "${__libsupcxx}" ) - message( FATAL_ERROR "The required libstdsupc++.a is missing in your standalone toolchain. - Usually it happens because of bug in make-standalone-toolchain.sh script from NDK r7, r7b and r7c. - You need to either upgrade to newer NDK or manually copy - $ANDROID_NDK/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a - to - ${__libsupcxx} - " ) - endif() - if( ANDROID_STL STREQUAL "gnustl_shared" ) - if( ARMEABI_V7A AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libgnustl_shared.so" ) - elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD AND EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libgnustl_shared.so" ) - elseif( EXISTS "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" ) - set( __libstl "${ANDROID_STANDALONE_TOOLCHAIN}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libgnustl_shared.so" ) - endif() - endif() - endif() -endif() - -# clang -if( "${ANDROID_TOOLCHAIN_NAME}" STREQUAL "standalone-clang" ) - set( ANDROID_COMPILER_IS_CLANG 1 ) - execute_process( COMMAND "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/clang${TOOL_OS_SUFFIX}" --version OUTPUT_VARIABLE ANDROID_CLANG_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ) - string( REGEX MATCH "[0-9]+[.][0-9]+" ANDROID_CLANG_VERSION "${ANDROID_CLANG_VERSION}") -elseif( "${ANDROID_TOOLCHAIN_NAME}" MATCHES "-clang3[.][0-9]?$" ) - string( REGEX MATCH "3[.][0-9]$" ANDROID_CLANG_VERSION "${ANDROID_TOOLCHAIN_NAME}") - string( REGEX REPLACE "-clang${ANDROID_CLANG_VERSION}$" "-${ANDROID_COMPILER_VERSION}" ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" ) - if( NOT EXISTS "${ANDROID_NDK_TOOLCHAINS_PATH}/llvm-${ANDROID_CLANG_VERSION}${ANDROID_NDK_TOOLCHAINS_SUBPATH}/bin/clang${TOOL_OS_SUFFIX}" ) - message( FATAL_ERROR "Could not find the Clang compiler driver" ) - endif() - set( ANDROID_COMPILER_IS_CLANG 1 ) - set( ANDROID_CLANG_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAINS_PATH}/llvm-${ANDROID_CLANG_VERSION}${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) -else() - set( ANDROID_GCC_TOOLCHAIN_NAME "${ANDROID_TOOLCHAIN_NAME}" ) - unset( ANDROID_COMPILER_IS_CLANG CACHE ) -endif() - -string( REPLACE "." "" _clang_name "clang${ANDROID_CLANG_VERSION}" ) -if( NOT EXISTS "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" ) - set( _clang_name "clang" ) -endif() - - -# setup paths and STL for NDK -if( BUILD_WITH_ANDROID_NDK ) - set( ANDROID_TOOLCHAIN_ROOT "${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}${ANDROID_NDK_TOOLCHAINS_SUBPATH}" ) - set( ANDROID_SYSROOT "${ANDROID_NDK}/platforms/android-${ANDROID_NATIVE_API_LEVEL}/arch-${ANDROID_ARCH_NAME}" ) - - if( ANDROID_STL STREQUAL "none" ) - # do nothing - elseif( ANDROID_STL STREQUAL "system" ) - set( ANDROID_RTTI OFF ) - set( ANDROID_EXCEPTIONS OFF ) - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" ) - elseif( ANDROID_STL STREQUAL "system_re" ) - set( ANDROID_RTTI ON ) - set( ANDROID_EXCEPTIONS ON ) - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/system/include" ) - elseif( ANDROID_STL MATCHES "gabi" ) - if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7 - message( FATAL_ERROR "gabi++ is not available in your NDK. You have to upgrade to NDK r7 or newer to use gabi++.") - endif() - set( ANDROID_RTTI ON ) - set( ANDROID_EXCEPTIONS OFF ) - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/gabi++/include" ) - set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gabi++/libs/${ANDROID_NDK_ABI_NAME}/libgabi++_static.a" ) - elseif( ANDROID_STL MATCHES "stlport" ) - if( NOT ANDROID_NDK_RELEASE_NUM LESS 8004 ) # before r8d - set( ANDROID_EXCEPTIONS ON ) - else() - set( ANDROID_EXCEPTIONS OFF ) - endif() - if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7 - set( ANDROID_RTTI OFF ) - else() - set( ANDROID_RTTI ON ) - endif() - set( ANDROID_STL_INCLUDE_DIRS "${ANDROID_NDK}/sources/cxx-stl/stlport/stlport" ) - set( __libstl "${ANDROID_NDK}/sources/cxx-stl/stlport/libs/${ANDROID_NDK_ABI_NAME}/libstlport_static.a" ) - elseif( ANDROID_STL MATCHES "gnustl" ) - set( ANDROID_EXCEPTIONS ON ) - set( ANDROID_RTTI ON ) - if( EXISTS "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" ) - if( ARMEABI_V7A AND ANDROID_COMPILER_VERSION VERSION_EQUAL "4.7" AND ANDROID_NDK_RELEASE STREQUAL "r8d" ) - # gnustl binary for 4.7 compiler is buggy :( - # TODO: look for right fix - set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/4.6" ) - else() - set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}" ) - endif() - else() - set( __libstl "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++" ) - endif() - set( ANDROID_STL_INCLUDE_DIRS "${__libstl}/include" "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/include" "${__libstl}/include/backward" ) - if( EXISTS "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a" ) - set( __libstl "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libgnustl_static.a" ) - else() - set( __libstl "${__libstl}/libs/${ANDROID_NDK_ABI_NAME}/libstdc++.a" ) - endif() - else() - message( FATAL_ERROR "Unknown runtime: ${ANDROID_STL}" ) - endif() - # find libsupc++.a - rtti & exceptions - if( ANDROID_STL STREQUAL "system_re" OR ANDROID_STL MATCHES "gnustl" ) - set( __libsupcxx "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/${ANDROID_COMPILER_VERSION}/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" ) # r8b or newer - if( NOT EXISTS "${__libsupcxx}" ) - set( __libsupcxx "${ANDROID_NDK}/sources/cxx-stl/gnu-libstdc++/libs/${ANDROID_NDK_ABI_NAME}/libsupc++.a" ) # r7-r8 - endif() - if( NOT EXISTS "${__libsupcxx}" ) # before r7 - if( ARMEABI_V7A ) - if( ANDROID_FORCE_ARM_BUILD ) - set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/libsupc++.a" ) - else() - set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/${CMAKE_SYSTEM_PROCESSOR}/thumb/libsupc++.a" ) - endif() - elseif( ARMEABI AND NOT ANDROID_FORCE_ARM_BUILD ) - set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/thumb/libsupc++.a" ) - else() - set( __libsupcxx "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}/lib/libsupc++.a" ) - endif() - endif() - if( NOT EXISTS "${__libsupcxx}") - message( ERROR "Could not find libsupc++.a for a chosen platform. Either your NDK is not supported or is broken.") - endif() - endif() -endif() - - -# case of shared STL linkage -if( ANDROID_STL MATCHES "shared" AND DEFINED __libstl ) - string( REPLACE "_static.a" "_shared.so" __libstl "${__libstl}" ) - # TODO: check if .so file exists before the renaming -endif() - - -# ccache support -__INIT_VARIABLE( _ndk_ccache NDK_CCACHE ENV_NDK_CCACHE ) -if( _ndk_ccache ) - if( DEFINED NDK_CCACHE AND NOT EXISTS NDK_CCACHE ) - unset( NDK_CCACHE CACHE ) - endif() - find_program( NDK_CCACHE "${_ndk_ccache}" DOC "The path to ccache binary") -else() - unset( NDK_CCACHE CACHE ) -endif() -unset( _ndk_ccache ) - - -# setup the cross-compiler -if( NOT CMAKE_C_COMPILER ) - if( NDK_CCACHE AND NOT ANDROID_SYSROOT MATCHES "[ ;\"]" ) - set( CMAKE_C_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C compiler" ) - set( CMAKE_CXX_COMPILER "${NDK_CCACHE}" CACHE PATH "ccache as C++ compiler" ) - if( ANDROID_COMPILER_IS_CLANG ) - set( CMAKE_C_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") - set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") - else() - set( CMAKE_C_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") - set( CMAKE_CXX_COMPILER_ARG1 "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") - endif() - else() - if( ANDROID_COMPILER_IS_CLANG ) - set( CMAKE_C_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}${TOOL_OS_SUFFIX}" CACHE PATH "C compiler") - set( CMAKE_CXX_COMPILER "${ANDROID_CLANG_TOOLCHAIN_ROOT}/bin/${_clang_name}++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler") - else() - set( CMAKE_C_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "C compiler" ) - set( CMAKE_CXX_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-g++${TOOL_OS_SUFFIX}" CACHE PATH "C++ compiler" ) - endif() - endif() - set( CMAKE_ASM_COMPILER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc${TOOL_OS_SUFFIX}" CACHE PATH "assembler" ) - set( CMAKE_STRIP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-strip${TOOL_OS_SUFFIX}" CACHE PATH "strip" ) - if( EXISTS "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc-ar${TOOL_OS_SUFFIX}" ) - # Use gcc-ar if we have it for better LTO support. - set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-gcc-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" ) - else() - set( CMAKE_AR "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ar${TOOL_OS_SUFFIX}" CACHE PATH "archive" ) - endif() - set( CMAKE_LINKER "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ld${TOOL_OS_SUFFIX}" CACHE PATH "linker" ) - set( CMAKE_NM "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-nm${TOOL_OS_SUFFIX}" CACHE PATH "nm" ) - set( CMAKE_OBJCOPY "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objcopy${TOOL_OS_SUFFIX}" CACHE PATH "objcopy" ) - set( CMAKE_OBJDUMP "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-objdump${TOOL_OS_SUFFIX}" CACHE PATH "objdump" ) - set( CMAKE_RANLIB "${ANDROID_TOOLCHAIN_ROOT}/bin/${ANDROID_TOOLCHAIN_MACHINE_NAME}-ranlib${TOOL_OS_SUFFIX}" CACHE PATH "ranlib" ) -endif() - -set( _CMAKE_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_MACHINE_NAME}-" ) -if( CMAKE_VERSION VERSION_LESS 2.8.5 ) - set( CMAKE_ASM_COMPILER_ARG1 "-c" ) -endif() -if( APPLE ) - find_program( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool ) - if( NOT CMAKE_INSTALL_NAME_TOOL ) - message( FATAL_ERROR "Could not find install_name_tool, please check your installation." ) - endif() - mark_as_advanced( CMAKE_INSTALL_NAME_TOOL ) -endif() - -# Force set compilers because standard identification works badly for us -include( CMakeForceCompiler ) -# CMAKE_FORCE_C_COMPILER( "${CMAKE_C_COMPILER}" GNU ) -if( ANDROID_COMPILER_IS_CLANG ) - set( CMAKE_C_COMPILER_ID Clang ) -endif() -set( CMAKE_C_PLATFORM_ID Linux ) -if( X86_64 OR MIPS64 OR ARM64_V8A ) - set( CMAKE_C_SIZEOF_DATA_PTR 8 ) -else() - set( CMAKE_C_SIZEOF_DATA_PTR 4 ) -endif() -set( CMAKE_C_HAS_ISYSROOT 1 ) -set( CMAKE_C_COMPILER_ABI ELF ) -# CMAKE_FORCE_CXX_COMPILER( "${CMAKE_CXX_COMPILER}" GNU ) -if( ANDROID_COMPILER_IS_CLANG ) - set( CMAKE_CXX_COMPILER_ID Clang) -endif() -set( CMAKE_CXX_PLATFORM_ID Linux ) -set( CMAKE_CXX_SIZEOF_DATA_PTR ${CMAKE_C_SIZEOF_DATA_PTR} ) -set( CMAKE_CXX_HAS_ISYSROOT 1 ) -set( CMAKE_CXX_COMPILER_ABI ELF ) -set( CMAKE_CXX_SOURCE_FILE_EXTENSIONS cc cp cxx cpp CPP c++ C ) -# force ASM compiler (required for CMake < 2.8.5) -set( CMAKE_ASM_COMPILER_ID_RUN TRUE ) -set( CMAKE_ASM_COMPILER_ID GNU ) -set( CMAKE_ASM_COMPILER_WORKS TRUE ) -set( CMAKE_ASM_COMPILER_FORCED TRUE ) -set( CMAKE_COMPILER_IS_GNUASM 1) -set( CMAKE_ASM_SOURCE_FILE_EXTENSIONS s S asm ) - -foreach( lang C CXX ASM ) - if( ANDROID_COMPILER_IS_CLANG ) - set( CMAKE_${lang}_COMPILER_VERSION ${ANDROID_CLANG_VERSION} ) - else() - set( CMAKE_${lang}_COMPILER_VERSION ${ANDROID_COMPILER_VERSION} ) - endif() -endforeach() - -# flags and definitions -remove_definitions( -DANDROID ) -add_definitions( -DANDROID ) - -if( ANDROID_SYSROOT MATCHES "[ ;\"]" ) - if( CMAKE_HOST_WIN32 ) - # try to convert path to 8.3 form - file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cvt83.cmd" "@echo %~s1" ) - execute_process( COMMAND "$ENV{ComSpec}" /c "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cvt83.cmd" "${ANDROID_SYSROOT}" - OUTPUT_VARIABLE __path OUTPUT_STRIP_TRAILING_WHITESPACE - RESULT_VARIABLE __result ERROR_QUIET ) - if( __result EQUAL 0 ) - file( TO_CMAKE_PATH "${__path}" ANDROID_SYSROOT ) - set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" ) - else() - set( ANDROID_CXX_FLAGS "--sysroot=\"${ANDROID_SYSROOT}\"" ) - endif() - else() - set( ANDROID_CXX_FLAGS "'--sysroot=${ANDROID_SYSROOT}'" ) - endif() - if( NOT _CMAKE_IN_TRY_COMPILE ) - # quotes can break try_compile and compiler identification - message(WARNING "Path to your Android NDK (or toolchain) has non-alphanumeric symbols.\nThe build might be broken.\n") - endif() -else() - set( ANDROID_CXX_FLAGS "--sysroot=${ANDROID_SYSROOT}" ) -endif() - -# NDK flags -if (ARM64_V8A ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" ) - set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer -fstrict-aliasing" ) - set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer -fno-strict-aliasing" ) - if( NOT ANDROID_COMPILER_IS_CLANG ) - set( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} -funswitch-loops -finline-limit=300" ) - endif() -elseif( ARMEABI OR ARMEABI_V7A) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" ) - if( NOT ANDROID_FORCE_ARM_BUILD AND NOT ARMEABI_V6 ) - set( ANDROID_CXX_FLAGS_RELEASE "-mthumb -fomit-frame-pointer -fno-strict-aliasing" ) - set( ANDROID_CXX_FLAGS_DEBUG "-marm -fno-omit-frame-pointer -fno-strict-aliasing" ) - if( NOT ANDROID_COMPILER_IS_CLANG ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -finline-limit=64" ) - endif() - else() - # always compile ARMEABI_V6 in arm mode; otherwise there is no difference from ARMEABI - set( ANDROID_CXX_FLAGS_RELEASE "-marm -fomit-frame-pointer -fstrict-aliasing" ) - set( ANDROID_CXX_FLAGS_DEBUG "-marm -fno-omit-frame-pointer -fno-strict-aliasing" ) - if( NOT ANDROID_COMPILER_IS_CLANG ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300" ) - endif() - endif() -elseif( X86 OR X86_64 ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funwind-tables" ) - if( NOT ANDROID_COMPILER_IS_CLANG ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -funswitch-loops -finline-limit=300" ) - endif() - set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer -fstrict-aliasing" ) - set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer -fno-strict-aliasing" ) -elseif( MIPS OR MIPS64 ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fno-strict-aliasing -finline-functions -funwind-tables -fmessage-length=0" ) - set( ANDROID_CXX_FLAGS_RELEASE "-fomit-frame-pointer" ) - set( ANDROID_CXX_FLAGS_DEBUG "-fno-omit-frame-pointer" ) - if( NOT ANDROID_COMPILER_IS_CLANG ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers" ) - set( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} -funswitch-loops -finline-limit=300" ) - endif() -elseif() - set( ANDROID_CXX_FLAGS_RELEASE "" ) - set( ANDROID_CXX_FLAGS_DEBUG "" ) -endif() - -set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fsigned-char" ) # good/necessary when porting desktop libraries - -if( NOT X86 AND NOT ANDROID_COMPILER_IS_CLANG ) - set( ANDROID_CXX_FLAGS "-Wno-psabi ${ANDROID_CXX_FLAGS}" ) -endif() - -if( NOT ANDROID_COMPILER_VERSION VERSION_LESS "4.6" ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -no-canonical-prefixes" ) # see https://android-review.googlesource.com/#/c/47564/ -endif() - -# ABI-specific flags -if( ARMEABI_V7A ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv7-a -mfloat-abi=softfp" ) - if( NEON ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=neon" ) - elseif( VFPV3 ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3" ) - else() - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -mfpu=vfpv3-d16" ) - endif() -elseif( ARMEABI_V6 ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv6 -mfloat-abi=softfp -mfpu=vfp" ) # vfp == vfpv2 -elseif( ARMEABI ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -march=armv5te -mtune=xscale -msoft-float" ) -endif() - -if( ANDROID_STL MATCHES "gnustl" AND (EXISTS "${__libstl}" OR EXISTS "${__libsupcxx}") ) - set( CMAKE_CXX_CREATE_SHARED_LIBRARY " -o " ) - set( CMAKE_CXX_CREATE_SHARED_MODULE " -o " ) - set( CMAKE_CXX_LINK_EXECUTABLE " -o " ) -else() - set( CMAKE_CXX_CREATE_SHARED_LIBRARY " -o " ) - set( CMAKE_CXX_CREATE_SHARED_MODULE " -o " ) - set( CMAKE_CXX_LINK_EXECUTABLE " -o " ) -endif() - -# STL -if( EXISTS "${__libstl}" OR EXISTS "${__libsupcxx}" ) - if( EXISTS "${__libstl}" ) - set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${__libstl}\"" ) - set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${__libstl}\"" ) - set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} \"${__libstl}\"" ) - endif() - if( EXISTS "${__libsupcxx}" ) - set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${__libsupcxx}\"" ) - set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${__libsupcxx}\"" ) - set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} \"${__libsupcxx}\"" ) - # C objects: - set( CMAKE_C_CREATE_SHARED_LIBRARY " -o " ) - set( CMAKE_C_CREATE_SHARED_MODULE " -o " ) - set( CMAKE_C_LINK_EXECUTABLE " -o " ) - set( CMAKE_C_CREATE_SHARED_LIBRARY "${CMAKE_C_CREATE_SHARED_LIBRARY} \"${__libsupcxx}\"" ) - set( CMAKE_C_CREATE_SHARED_MODULE "${CMAKE_C_CREATE_SHARED_MODULE} \"${__libsupcxx}\"" ) - set( CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} \"${__libsupcxx}\"" ) - endif() - if( ANDROID_STL MATCHES "gnustl" ) - if( NOT EXISTS "${ANDROID_LIBM_PATH}" ) - set( ANDROID_LIBM_PATH -lm ) - endif() - set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} ${ANDROID_LIBM_PATH}" ) - set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} ${ANDROID_LIBM_PATH}" ) - set( CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${ANDROID_LIBM_PATH}" ) - endif() -endif() - -# variables controlling optional build flags -if( ANDROID_NDK_RELEASE_NUM LESS 7000 ) # before r7 - # libGLESv2.so in NDK's prior to r7 refers to missing external symbols. - # So this flag option is required for all projects using OpenGL from native. - __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES ON ) -else() - __INIT_VARIABLE( ANDROID_SO_UNDEFINED VALUES OFF ) -endif() -__INIT_VARIABLE( ANDROID_NO_UNDEFINED VALUES ON ) -__INIT_VARIABLE( ANDROID_FUNCTION_LEVEL_LINKING VALUES ON ) -__INIT_VARIABLE( ANDROID_GOLD_LINKER VALUES ON ) -__INIT_VARIABLE( ANDROID_NOEXECSTACK VALUES ON ) -__INIT_VARIABLE( ANDROID_RELRO VALUES ON ) - -set( ANDROID_NO_UNDEFINED ${ANDROID_NO_UNDEFINED} CACHE BOOL "Show all undefined symbols as linker errors" ) -set( ANDROID_SO_UNDEFINED ${ANDROID_SO_UNDEFINED} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" ) -set( ANDROID_FUNCTION_LEVEL_LINKING ${ANDROID_FUNCTION_LEVEL_LINKING} CACHE BOOL "Put each function in separate section and enable garbage collection of unused input sections at link time" ) -set( ANDROID_GOLD_LINKER ${ANDROID_GOLD_LINKER} CACHE BOOL "Enables gold linker" ) -set( ANDROID_NOEXECSTACK ${ANDROID_NOEXECSTACK} CACHE BOOL "Allows or disallows undefined symbols in shared libraries" ) -set( ANDROID_RELRO ${ANDROID_RELRO} CACHE BOOL "Enables RELRO - a memory corruption mitigation technique" ) -mark_as_advanced( ANDROID_NO_UNDEFINED ANDROID_SO_UNDEFINED ANDROID_FUNCTION_LEVEL_LINKING ANDROID_GOLD_LINKER ANDROID_NOEXECSTACK ANDROID_RELRO ) - -# linker flags -set( ANDROID_LINKER_FLAGS "" ) - -if( ARMEABI_V7A ) - # this is *required* to use the following linker flags that routes around - # a CPU bug in some Cortex-A8 implementations: - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--fix-cortex-a8" ) -endif() - -if( ANDROID_NO_UNDEFINED ) - if( MIPS ) - # there is some sysroot-related problem in mips linker... - if( NOT ANDROID_SYSROOT MATCHES "[ ;\"]" ) - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--no-undefined -Wl,-rpath-link,${ANDROID_SYSROOT}/usr/lib" ) - endif() - else() - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--no-undefined" ) - endif() -endif() - -if( ANDROID_SO_UNDEFINED ) - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-allow-shlib-undefined" ) -endif() - -if( ANDROID_FUNCTION_LEVEL_LINKING ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -fdata-sections -ffunction-sections" ) - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,--gc-sections" ) -endif() - -if( ANDROID_COMPILER_VERSION VERSION_EQUAL "4.6" ) - if( ANDROID_GOLD_LINKER AND (CMAKE_HOST_UNIX OR ANDROID_NDK_RELEASE_NUM GREATER 8002) AND (ARMEABI OR ARMEABI_V7A OR X86) ) - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=gold" ) - elseif( ANDROID_NDK_RELEASE_NUM GREATER 8002 ) # after r8b - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -fuse-ld=bfd" ) - elseif( ANDROID_NDK_RELEASE STREQUAL "r8b" AND ARMEABI AND NOT _CMAKE_IN_TRY_COMPILE ) - message( WARNING "The default bfd linker from arm GCC 4.6 toolchain can fail with 'unresolvable R_ARM_THM_CALL relocation' error message. See https://code.google.com/p/android/issues/detail?id=35342 - On Linux and OS X host platform you can workaround this problem using gold linker (default). - Rerun cmake with -DANDROID_GOLD_LINKER=ON option in case of problems. -" ) - endif() -endif() # version 4.6 - -if( ANDROID_NOEXECSTACK ) - if( ANDROID_COMPILER_IS_CLANG ) - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Xclang -mnoexecstack" ) - else() - set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS} -Wa,--noexecstack" ) - endif() - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,noexecstack" ) -endif() - -if( ANDROID_RELRO ) - set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} -Wl,-z,relro -Wl,-z,now" ) -endif() - -if( ANDROID_COMPILER_IS_CLANG ) - set( ANDROID_CXX_FLAGS "-target ${ANDROID_LLVM_TRIPLE} -Qunused-arguments ${ANDROID_CXX_FLAGS}" ) - if( BUILD_WITH_ANDROID_NDK ) - set( ANDROID_CXX_FLAGS "-gcc-toolchain ${ANDROID_TOOLCHAIN_ROOT} ${ANDROID_CXX_FLAGS}" ) - endif() -endif() - -# cache flags -set( CMAKE_CXX_FLAGS "" CACHE STRING "c++ flags" ) -set( CMAKE_C_FLAGS "" CACHE STRING "c flags" ) -set( CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c++ Release flags" ) -set( CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG" CACHE STRING "c Release flags" ) -set( CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c++ Debug flags" ) -set( CMAKE_C_FLAGS_DEBUG "-O0 -g -DDEBUG -D_DEBUG" CACHE STRING "c Debug flags" ) -set( CMAKE_SHARED_LINKER_FLAGS "-Wl,--build-id" CACHE STRING "shared linker flags" ) -set( CMAKE_MODULE_LINKER_FLAGS "-Wl,--build-id" CACHE STRING "module linker flags" ) -set( CMAKE_EXE_LINKER_FLAGS "-Wl,--build-id -Wl,-z,nocopyreloc" CACHE STRING "executable linker flags" ) - -# put flags to cache (for debug purpose only) -set( ANDROID_CXX_FLAGS "${ANDROID_CXX_FLAGS}" CACHE INTERNAL "Android specific c/c++ flags" ) -set( ANDROID_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE}" CACHE INTERNAL "Android specific c/c++ Release flags" ) -set( ANDROID_CXX_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG}" CACHE INTERNAL "Android specific c/c++ Debug flags" ) -set( ANDROID_LINKER_FLAGS "${ANDROID_LINKER_FLAGS}" CACHE INTERNAL "Android specific c/c++ linker flags" ) - -# finish flags -set( CMAKE_CXX_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_CXX_FLAGS}" ) -set( CMAKE_C_FLAGS "${ANDROID_CXX_FLAGS} ${CMAKE_C_FLAGS}" ) -set( CMAKE_CXX_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_RELEASE}" ) -set( CMAKE_C_FLAGS_RELEASE "${ANDROID_CXX_FLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}" ) -set( CMAKE_CXX_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_DEBUG}" ) -set( CMAKE_C_FLAGS_DEBUG "${ANDROID_CXX_FLAGS_DEBUG} ${CMAKE_C_FLAGS_DEBUG}" ) -set( CMAKE_SHARED_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}" ) -set( CMAKE_MODULE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}" ) -set( CMAKE_EXE_LINKER_FLAGS "${ANDROID_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}" ) - -if( MIPS AND BUILD_WITH_ANDROID_NDK AND ANDROID_NDK_RELEASE STREQUAL "r8" ) - set( CMAKE_SHARED_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_SHARED_LINKER_FLAGS}" ) - set( CMAKE_MODULE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.xsc ${CMAKE_MODULE_LINKER_FLAGS}" ) - set( CMAKE_EXE_LINKER_FLAGS "-Wl,-T,${ANDROID_NDK_TOOLCHAINS_PATH}/${ANDROID_GCC_TOOLCHAIN_NAME}/mipself.x ${CMAKE_EXE_LINKER_FLAGS}" ) -endif() - -# pie/pic -if( NOT (ANDROID_NATIVE_API_LEVEL LESS 16) AND (NOT DEFINED ANDROID_APP_PIE OR ANDROID_APP_PIE) AND (CMAKE_VERSION VERSION_GREATER 2.8.8) ) - set( CMAKE_POSITION_INDEPENDENT_CODE TRUE ) - set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie") -else() - set( CMAKE_POSITION_INDEPENDENT_CODE FALSE ) - set( CMAKE_CXX_FLAGS "-fpic ${CMAKE_CXX_FLAGS}" ) - set( CMAKE_C_FLAGS "-fpic ${CMAKE_C_FLAGS}" ) -endif() - -# configure rtti -if( DEFINED ANDROID_RTTI AND ANDROID_STL_FORCE_FEATURES ) - if( ANDROID_RTTI ) - set( CMAKE_CXX_FLAGS "-frtti ${CMAKE_CXX_FLAGS}" ) - else() - set( CMAKE_CXX_FLAGS "-fno-rtti ${CMAKE_CXX_FLAGS}" ) - endif() -endif() - -# configure exceptios -if( DEFINED ANDROID_EXCEPTIONS AND ANDROID_STL_FORCE_FEATURES ) - if( ANDROID_EXCEPTIONS ) - set( CMAKE_CXX_FLAGS "-fexceptions ${CMAKE_CXX_FLAGS}" ) - set( CMAKE_C_FLAGS "-fexceptions ${CMAKE_C_FLAGS}" ) - else() - set( CMAKE_CXX_FLAGS "-fno-exceptions ${CMAKE_CXX_FLAGS}" ) - set( CMAKE_C_FLAGS "-fno-exceptions ${CMAKE_C_FLAGS}" ) - endif() -endif() - -# global includes and link directories -include_directories( SYSTEM "${ANDROID_SYSROOT}/usr/include" ${ANDROID_STL_INCLUDE_DIRS} ) -get_filename_component(__android_install_path "${CMAKE_INSTALL_PREFIX}/libs/${ANDROID_NDK_ABI_NAME}" ABSOLUTE) # avoid CMP0015 policy warning -link_directories( "${__android_install_path}" ) - -# detect if need link crtbegin_so.o explicitly -if( NOT DEFINED ANDROID_EXPLICIT_CRT_LINK ) - set( __cmd "${CMAKE_CXX_CREATE_SHARED_LIBRARY}" ) - string( REPLACE "" "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" __cmd "${__cmd}" ) - string( REPLACE "" "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}" __cmd "${__cmd}" ) - string( REPLACE "" "${CMAKE_CXX_FLAGS}" __cmd "${__cmd}" ) - string( REPLACE "" "" __cmd "${__cmd}" ) - string( REPLACE "" "${CMAKE_SHARED_LINKER_FLAGS}" __cmd "${__cmd}" ) - string( REPLACE "" "-shared" __cmd "${__cmd}" ) - string( REPLACE "" "" __cmd "${__cmd}" ) - string( REPLACE "" "" __cmd "${__cmd}" ) - string( REPLACE "" "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/toolchain_crtlink_test.so" __cmd "${__cmd}" ) - string( REPLACE "" "\"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\"" __cmd "${__cmd}" ) - string( REPLACE "" "" __cmd "${__cmd}" ) - separate_arguments( __cmd ) - foreach( __var ANDROID_NDK ANDROID_NDK_TOOLCHAINS_PATH ANDROID_STANDALONE_TOOLCHAIN ) - if( ${__var} ) - set( __tmp "${${__var}}" ) - separate_arguments( __tmp ) - string( REPLACE "${__tmp}" "${${__var}}" __cmd "${__cmd}") - endif() - endforeach() - string( REPLACE "'" "" __cmd "${__cmd}" ) - string( REPLACE "\"" "" __cmd "${__cmd}" ) - execute_process( COMMAND ${__cmd} RESULT_VARIABLE __cmd_result OUTPUT_QUIET ERROR_QUIET ) - if( __cmd_result EQUAL 0 ) - set( ANDROID_EXPLICIT_CRT_LINK ON ) - else() - set( ANDROID_EXPLICIT_CRT_LINK OFF ) - endif() -endif() - -if( ANDROID_EXPLICIT_CRT_LINK ) - set( CMAKE_CXX_CREATE_SHARED_LIBRARY "${CMAKE_CXX_CREATE_SHARED_LIBRARY} \"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\"" ) - set( CMAKE_CXX_CREATE_SHARED_MODULE "${CMAKE_CXX_CREATE_SHARED_MODULE} \"${ANDROID_SYSROOT}/usr/lib/crtbegin_so.o\"" ) -endif() - -# setup output directories -set( CMAKE_INSTALL_PREFIX "${ANDROID_TOOLCHAIN_ROOT}/user" CACHE STRING "path for installing" ) - -if( DEFINED LIBRARY_OUTPUT_PATH_ROOT - OR EXISTS "${CMAKE_SOURCE_DIR}/AndroidManifest.xml" - OR (EXISTS "${CMAKE_SOURCE_DIR}/../AndroidManifest.xml" AND EXISTS "${CMAKE_SOURCE_DIR}/../jni/") ) - set( LIBRARY_OUTPUT_PATH_ROOT ${CMAKE_SOURCE_DIR} CACHE PATH "Root for binaries output, set this to change where Android libs are installed to" ) - if( NOT _CMAKE_IN_TRY_COMPILE ) - if( EXISTS "${CMAKE_SOURCE_DIR}/jni/CMakeLists.txt" ) - set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for applications" ) - else() - set( EXECUTABLE_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/bin" CACHE PATH "Output directory for applications" ) - endif() - set( LIBRARY_OUTPUT_PATH "${LIBRARY_OUTPUT_PATH_ROOT}/libs/${ANDROID_NDK_ABI_NAME}" CACHE PATH "Output directory for Android libs" ) - endif() -endif() - -# copy shaed stl library to build directory -if( NOT _CMAKE_IN_TRY_COMPILE AND __libstl MATCHES "[.]so$" AND DEFINED LIBRARY_OUTPUT_PATH ) - get_filename_component( __libstlname "${__libstl}" NAME ) - execute_process( COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${__libstl}" "${LIBRARY_OUTPUT_PATH}/${__libstlname}" RESULT_VARIABLE __fileCopyProcess ) - if( NOT __fileCopyProcess EQUAL 0 OR NOT EXISTS "${LIBRARY_OUTPUT_PATH}/${__libstlname}") - message( SEND_ERROR "Failed copying of ${__libstl} to the ${LIBRARY_OUTPUT_PATH}/${__libstlname}" ) - endif() - unset( __fileCopyProcess ) - unset( __libstlname ) -endif() - - -# set these global flags for cmake client scripts to change behavior -set( ANDROID True ) -set( BUILD_ANDROID True ) - -# where is the target environment -set( CMAKE_FIND_ROOT_PATH "${ANDROID_TOOLCHAIN_ROOT}/bin" "${ANDROID_TOOLCHAIN_ROOT}/${ANDROID_TOOLCHAIN_MACHINE_NAME}" "${ANDROID_SYSROOT}" "${CMAKE_INSTALL_PREFIX}" "${CMAKE_INSTALL_PREFIX}/share" ) - -# only search for libraries and includes in the ndk toolchain -set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) -set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) -set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) - - -# macro to find packages on the host OS -macro( find_host_package ) - set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) - set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) - set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) - if( CMAKE_HOST_WIN32 ) - SET( WIN32 1 ) - SET( UNIX ) - elseif( CMAKE_HOST_APPLE ) - SET( APPLE 1 ) - SET( UNIX ) - endif() - find_package( ${ARGN} ) - SET( WIN32 ) - SET( APPLE ) - SET( UNIX 1 ) - set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) - set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) - set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) -endmacro() - - -# macro to find programs on the host OS -macro( find_host_program ) - set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER ) - set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER ) - set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER ) - if( CMAKE_HOST_WIN32 ) - SET( WIN32 1 ) - SET( UNIX ) - elseif( CMAKE_HOST_APPLE ) - SET( APPLE 1 ) - SET( UNIX ) - endif() - find_program( ${ARGN} ) - SET( WIN32 ) - SET( APPLE ) - SET( UNIX 1 ) - set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY ) - set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY ) - set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY ) -endmacro() - - -# export toolchain settings for the try_compile() command -if( NOT _CMAKE_IN_TRY_COMPILE ) - set( __toolchain_config "") - foreach( __var NDK_CCACHE LIBRARY_OUTPUT_PATH_ROOT ANDROID_FORBID_SYGWIN - ANDROID_NDK_HOST_X64 - ANDROID_NDK - ANDROID_NDK_LAYOUT - ANDROID_STANDALONE_TOOLCHAIN - ANDROID_TOOLCHAIN_NAME - ANDROID_ABI - ANDROID_NATIVE_API_LEVEL - ANDROID_STL - ANDROID_STL_FORCE_FEATURES - ANDROID_FORCE_ARM_BUILD - ANDROID_NO_UNDEFINED - ANDROID_SO_UNDEFINED - ANDROID_FUNCTION_LEVEL_LINKING - ANDROID_GOLD_LINKER - ANDROID_NOEXECSTACK - ANDROID_RELRO - ANDROID_LIBM_PATH - ANDROID_EXPLICIT_CRT_LINK - ANDROID_APP_PIE - ) - if( DEFINED ${__var} ) - if( ${__var} MATCHES " ") - set( __toolchain_config "${__toolchain_config}set( ${__var} \"${${__var}}\" CACHE INTERNAL \"\" )\n" ) - else() - set( __toolchain_config "${__toolchain_config}set( ${__var} ${${__var}} CACHE INTERNAL \"\" )\n" ) - endif() - endif() - endforeach() - file( WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/android.toolchain.config.cmake" "${__toolchain_config}" ) - unset( __toolchain_config ) -endif() - - -# force cmake to produce / instead of \ in build commands for Ninja generator -if( CMAKE_GENERATOR MATCHES "Ninja" AND CMAKE_HOST_WIN32 ) - # it is a bad hack after all - # CMake generates Ninja makefiles with UNIX paths only if it thinks that we are going to build with MinGW - set( CMAKE_COMPILER_IS_MINGW TRUE ) # tell CMake that we are MinGW - set( CMAKE_CROSSCOMPILING TRUE ) # stop recursion - enable_language( C ) - enable_language( CXX ) - # unset( CMAKE_COMPILER_IS_MINGW ) # can't unset because CMake does not convert back-slashes in response files without it - unset( MINGW ) -endif() - -# Variables need by cmAndroidGradleBuild to generate android_gradle_build.json -set(CMAKE_ANDROID_ARCH_ABI ${ANDROID_ABI}) - - -# Variables controlling behavior or set by cmake toolchain: -# ANDROID_ABI : "armeabi-v7a" (default), "armeabi", "armeabi-v7a with NEON", "armeabi-v7a with VFPV3", "armeabi-v6 with VFP", "x86", "mips", "arm64-v8a", "x86_64", "mips64" -# ANDROID_NATIVE_API_LEVEL : 3,4,5,8,9,14,15,16,17,18,19,21 (depends on NDK version) -# ANDROID_STL : gnustl_static/gnustl_shared/stlport_static/stlport_shared/gabi++_static/gabi++_shared/system_re/system/none -# ANDROID_FORBID_SYGWIN : ON/OFF -# ANDROID_NO_UNDEFINED : ON/OFF -# ANDROID_SO_UNDEFINED : OFF/ON (default depends on NDK version) -# ANDROID_FUNCTION_LEVEL_LINKING : ON/OFF -# ANDROID_GOLD_LINKER : ON/OFF -# ANDROID_NOEXECSTACK : ON/OFF -# ANDROID_RELRO : ON/OFF -# ANDROID_FORCE_ARM_BUILD : ON/OFF -# ANDROID_STL_FORCE_FEATURES : ON/OFF -# ANDROID_LIBM_PATH : path to libm.so (set to something like $(TOP)/out/target/product//obj/lib/libm.so) to workaround unresolved `sincos` -# Can be set only at the first run: -# ANDROID_NDK : path to your NDK install -# NDK_CCACHE : path to your ccache executable -# ANDROID_TOOLCHAIN_NAME : the NDK name of compiler toolchain -# ANDROID_NDK_HOST_X64 : try to use x86_64 toolchain (default for x64 host systems) -# ANDROID_NDK_LAYOUT : the inner NDK structure (RELEASE, LINARO, ANDROID) -# LIBRARY_OUTPUT_PATH_ROOT : -# ANDROID_STANDALONE_TOOLCHAIN -# -# Primary read-only variables: -# ANDROID : always TRUE -# ARMEABI : TRUE for arm v6 and older devices -# ARMEABI_V6 : TRUE for arm v6 -# ARMEABI_V7A : TRUE for arm v7a -# ARM64_V8A : TRUE for arm64-v8a -# NEON : TRUE if NEON unit is enabled -# VFPV3 : TRUE if VFP version 3 is enabled -# X86 : TRUE if configured for x86 -# X86_64 : TRUE if configured for x86_64 -# MIPS : TRUE if configured for mips -# MIPS64 : TRUE if configured for mips64 -# BUILD_WITH_ANDROID_NDK : TRUE if NDK is used -# BUILD_WITH_STANDALONE_TOOLCHAIN : TRUE if standalone toolchain is used -# ANDROID_NDK_HOST_SYSTEM_NAME : "windows", "linux-x86" or "darwin-x86" depending on host platform -# ANDROID_NDK_ABI_NAME : "armeabi", "armeabi-v7a", "x86", "mips", "arm64-v8a", "x86_64", "mips64" depending on ANDROID_ABI -# ANDROID_NDK_RELEASE : from r5 to r10d; set only for NDK -# ANDROID_NDK_RELEASE_NUM : numeric ANDROID_NDK_RELEASE version (1000*major+minor) -# ANDROID_ARCH_NAME : "arm", "x86", "mips", "arm64", "x86_64", "mips64" depending on ANDROID_ABI -# ANDROID_SYSROOT : path to the compiler sysroot -# TOOL_OS_SUFFIX : "" or ".exe" depending on host platform -# ANDROID_COMPILER_IS_CLANG : TRUE if clang compiler is used -# -# Secondary (less stable) read-only variables: -# ANDROID_COMPILER_VERSION : GCC version used (not Clang version) -# ANDROID_CLANG_VERSION : version of clang compiler if clang is used -# ANDROID_CXX_FLAGS : C/C++ compiler flags required by Android platform -# ANDROID_SUPPORTED_ABIS : list of currently allowed values for ANDROID_ABI -# ANDROID_TOOLCHAIN_MACHINE_NAME : "arm-linux-androideabi", "arm-eabi" or "i686-android-linux" -# ANDROID_TOOLCHAIN_ROOT : path to the top level of toolchain (standalone or placed inside NDK) -# ANDROID_CLANG_TOOLCHAIN_ROOT : path to clang tools -# ANDROID_SUPPORTED_NATIVE_API_LEVELS : list of native API levels found inside NDK -# ANDROID_STL_INCLUDE_DIRS : stl include paths -# ANDROID_RTTI : if rtti is enabled by the runtime -# ANDROID_EXCEPTIONS : if exceptions are enabled by the runtime -# ANDROID_GCC_TOOLCHAIN_NAME : read-only, differs from ANDROID_TOOLCHAIN_NAME only if clang is used -# -# Defaults: -# ANDROID_DEFAULT_NDK_API_LEVEL -# ANDROID_DEFAULT_NDK_API_LEVEL_${ARCH} -# ANDROID_NDK_SEARCH_PATHS -# ANDROID_SUPPORTED_ABIS_${ARCH} -# ANDROID_SUPPORTED_NDK_VERSIONS diff --git a/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp b/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp index 89849efc4f..62eb7e9837 100644 --- a/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp +++ b/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp @@ -161,20 +161,19 @@ JNIEXPORT jboolean JNICALL Java_io_realm_SyncSession_nativeWaitForDownloadComple "(ILjava/lang/Long;Ljava/lang/String;)V"); JavaGlobalRef java_session_object_ref(env, session_object); - bool listener_registered = - session->wait_for_download_completion([java_session_object_ref, callback_id](std::error_code error) { - JNIEnv* env = JniUtils::get_env(true); - JavaLocalRef java_error_code; - JavaLocalRef java_error_message; - if (error != std::error_code{}) { - java_error_code = - JavaLocalRef(env, JavaClassGlobalDef::new_long(env, error.value())); - java_error_message = JavaLocalRef(env, env->NewStringUTF(error.message().c_str())); - } - env->CallVoidMethod(java_session_object_ref.get(), java_notify_result_method, - callback_id, java_error_code.get(), java_error_message.get()); - }); - + // FIXME + std::function callback = [&java_session_object_ref, callback_id](std::error_code error) { + JNIEnv* env = JniUtils::get_env(true); + JavaLocalRef java_error_code; + JavaLocalRef java_error_message; + if (error != std::error_code{}) { + java_error_code = JavaLocalRef(env, JavaClassGlobalDef::new_long(env, error.value())); + java_error_message = JavaLocalRef(env, env->NewStringUTF(error.message().c_str())); + } + env->CallVoidMethod(java_session_object_ref.get(), java_notify_result_method, + callback_id, java_error_code.get(), java_error_message.get()); + }; + bool listener_registered = session->wait_for_download_completion(callback); return to_jbool(listener_registered); } } @@ -198,8 +197,9 @@ JNIEXPORT jboolean JNICALL Java_io_realm_SyncSession_nativeWaitForUploadCompleti "(ILjava/lang/Long;Ljava/lang/String;)V"); JavaGlobalRef java_session_object_ref(env, session_object); + // FIXME bool listener_registered = - session->wait_for_upload_completion([java_session_object_ref, callback_id](std::error_code error) { + session->wait_for_upload_completion([&java_session_object_ref, callback_id](std::error_code error) { JNIEnv* env = JniUtils::get_env(true); JavaLocalRef java_error_code; JavaLocalRef java_error_message; diff --git a/realm/realm-library/src/main/cpp/io_realm_internal_OsRealmConfig.cpp b/realm/realm-library/src/main/cpp/io_realm_internal_OsRealmConfig.cpp index e2b1c7d7bd..753b5ffbb8 100644 --- a/realm/realm-library/src/main/cpp/io_realm_internal_OsRealmConfig.cpp +++ b/realm/realm-library/src/main/cpp/io_realm_internal_OsRealmConfig.cpp @@ -302,7 +302,7 @@ JNIEXPORT jstring JNICALL Java_io_realm_internal_OsRealmConfig_nativeCreateAndSe case ECONNABORTED: error_code = 113; break; default: /* Do nothing */ - error_code = error_code; + (void)0; } } else if (std::strcmp(error_category, "realm.util.misc_ext") == 0) { switch (util::MiscExtErrors(error_code)) { @@ -311,7 +311,7 @@ JNIEXPORT jstring JNICALL Java_io_realm_internal_OsRealmConfig_nativeCreateAndSe case util::MiscExtErrors::delim_not_found: error_code = 3; break; default: /* Do nothing */ - error_code = error_code; + (void)0; } } diff --git a/realm/realm-library/src/main/cpp/jni_impl/android_logger.hpp b/realm/realm-library/src/main/cpp/jni_impl/android_logger.hpp index 53bd485407..92904d6fe5 100644 --- a/realm/realm-library/src/main/cpp/jni_impl/android_logger.hpp +++ b/realm/realm-library/src/main/cpp/jni_impl/android_logger.hpp @@ -24,7 +24,7 @@ namespace realm { namespace jni_impl { // Default logger implementation for Android. -class AndroidLogger : public realm::jni_util::JniLogger { +class AndroidLogger final: public realm::jni_util::JniLogger { public: static std::shared_ptr shared(); diff --git a/realm/realm-library/src/main/cpp/jni_util/log.cpp b/realm/realm-library/src/main/cpp/jni_util/log.cpp index 14026e3ccc..a3492f883c 100644 --- a/realm/realm-library/src/main/cpp/jni_util/log.cpp +++ b/realm/realm-library/src/main/cpp/jni_util/log.cpp @@ -62,6 +62,10 @@ JniLogger::JniLogger() { } +JniLogger::~JniLogger() +{ +} + JniLogger::JniLogger(bool is_java_logger) : m_is_java_logger(is_java_logger) { diff --git a/realm/realm-library/src/main/cpp/jni_util/log.hpp b/realm/realm-library/src/main/cpp/jni_util/log.hpp index db61e5fc7a..a669a6855d 100644 --- a/realm/realm-library/src/main/cpp/jni_util/log.hpp +++ b/realm/realm-library/src/main/cpp/jni_util/log.hpp @@ -164,6 +164,7 @@ class Log { class JniLogger { protected: JniLogger(); + virtual ~JniLogger(); // Used by JavaLogger. JniLogger(bool is_java_logger); // Indicate if this is a wrapper for Java RealmLogger class. See JavaLogger diff --git a/realm/realm-library/src/main/cpp/object-store b/realm/realm-library/src/main/cpp/object-store index f964c2640f..5654aaff4c 160000 --- a/realm/realm-library/src/main/cpp/object-store +++ b/realm/realm-library/src/main/cpp/object-store @@ -1 +1 @@ -Subproject commit f964c2640f635e76839559cb703732e9e906ba4c +Subproject commit 5654aaff4cb2e8c5d0e431c77268c71e4c1d0703 From afafdfb09a4ec1146f8461f148284423985bebe5 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Tue, 14 May 2019 08:05:06 +0200 Subject: [PATCH 06/47] Fix C++ cast error --- realm/build.gradle | 3 ++- .../realm-library/src/main/cpp/io_realm_internal_OsObject.cpp | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/realm/build.gradle b/realm/build.gradle index 834996e68c..aa18132037 100644 --- a/realm/build.gradle +++ b/realm/build.gradle @@ -37,7 +37,8 @@ allprojects { def projectDependencies = new Properties() projectDependencies.load(new FileInputStream("${rootDir}/../dependencies.list")) - project.ext.minSdkVersion = 21 // FIXME: Should be 16. Set to 21 currently due to OpenSSL + // FIXME: Should be 16. Set to 21 currently due to OpenSSL + project.ext.minSdkVersion = 16 project.ext.compileSdkVersion = 26 project.ext.buildToolsVersion = projectDependencies.get("ANDROID_BUILD_TOOLS") diff --git a/realm/realm-library/src/main/cpp/io_realm_internal_OsObject.cpp b/realm/realm-library/src/main/cpp/io_realm_internal_OsObject.cpp index 66278fbcfd..3df213d5b9 100644 --- a/realm/realm-library/src/main/cpp/io_realm_internal_OsObject.cpp +++ b/realm/realm-library/src/main/cpp/io_realm_internal_OsObject.cpp @@ -193,8 +193,7 @@ static inline size_t do_create_row_with_primary_key(JNIEnv* env, jlong shared_re } else { if (table.find_first_int(pk_column_ndx, pk_value) != npos) { - THROW_JAVA_EXCEPTION(env, PK_CONSTRAINT_EXCEPTION_CLASS, - format(PK_EXCEPTION_MSG_FORMAT, reinterpret_cast(pk_value))); + THROW_JAVA_EXCEPTION(env, PK_CONSTRAINT_EXCEPTION_CLASS, format(PK_EXCEPTION_MSG_FORMAT, pk_value)); } } From 3d1865c78dd0a910128ac844b90a0963f4fe6597 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Wed, 15 May 2019 15:30:29 +0200 Subject: [PATCH 07/47] Build locally --- dependencies.list | 6 +++--- realm/realm-library/src/main/cpp/CMakeLists.txt | 4 ++-- realm/realm-library/src/main/cpp/object-store | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dependencies.list b/dependencies.list index 48b5b292ce..151e648422 100644 --- a/dependencies.list +++ b/dependencies.list @@ -1,7 +1,7 @@ # Realm Sync release used by Realm Java (This includes Realm Core) # https://github.com/realm/realm-sync/releases -REALM_SYNC_VERSION=4.4.2 -REALM_SYNC_SHA256=7f3386bc9e590788afc6fd61744dd187148862513ddbd7e65c32d1d9c371e1ce +REALM_SYNC_VERSION=5.0.0 +REALM_SYNC_SHA256= # Object Server Release used by Integration tests. Installed using NPM. # Use `npm view realm-object-server versions` to get a list of available versions. @@ -14,6 +14,6 @@ ANDROID_BUILD_TOOLS=28.0.3 # Common classpath dependencies # Gradle 5 is not supported yet: https://issuetracker.google.com/issues/126433059 gradleVersion=4.10.1 -ndkVersion=r10e +ndkVersion=18.1.5063045 BUILD_INFO_EXTRACTOR_GRADLE=4.7.5 GRADLE_BINTRAY_PLUGIN=1.8.4 diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index 337e3f7ab9..323d6cf27c 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -108,7 +108,7 @@ use_realm_core(${build_SYNC} "${REALM_CORE_DIST_DIR}" "${CORE_SOURCE_PATH}") #string(TOLOWER "${CMAKE_BUILD_TYPE}" openssl_build_TYPE) set(openssl_build_TYPE "release") # FIXME Read the openssl version from core when the core/sync release has that information. -set(openssl_VERSION "1.1.1a") +set(openssl_VERSION "1.1.1b") set(openssl_BUILD_NUMBER "1") # set(openssl_FILENAME "openssl-${openssl_build_TYPE}-${openssl_VERSION}-${openssl_BUILD_NUMBER}-Android-${ANDROID_ABI}.tar.gz") set (openssl_FILENAME "openssl.tgz") @@ -158,7 +158,7 @@ endif() set(WARNING_CXX_FLAGS "-Werror -Wall -Wextra -pedantic -Wmissing-declarations \ -Wempty-body -Wparentheses -Wunknown-pragmas -Wunreachable-code \ -Wno-missing-field-initializers -Wno-uninitialized") -set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -pthread -fPIC -fvisibility=hidden -std=c++14 -fsigned-char") +set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -pthread -fPIC -frtti -fvisibility=hidden -std=c++14 -fsigned-char") if (build_SYNC) set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ENABLE_SYNC=1") endif() diff --git a/realm/realm-library/src/main/cpp/object-store b/realm/realm-library/src/main/cpp/object-store index 5654aaff4c..7671d4de33 160000 --- a/realm/realm-library/src/main/cpp/object-store +++ b/realm/realm-library/src/main/cpp/object-store @@ -1 +1 @@ -Subproject commit 5654aaff4cb2e8c5d0e431c77268c71e4c1d0703 +Subproject commit 7671d4de33481b2bf7fb763522b5cb3bc889d981 From 58630451dfd1f8a6929a29e03c2e6e06ffca9e9d Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 16 May 2019 15:53:29 +0200 Subject: [PATCH 08/47] Use proper release --- dependencies.list | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies.list b/dependencies.list index 151e648422..68c815ee9d 100644 --- a/dependencies.list +++ b/dependencies.list @@ -1,6 +1,6 @@ # Realm Sync release used by Realm Java (This includes Realm Core) # https://github.com/realm/realm-sync/releases -REALM_SYNC_VERSION=5.0.0 +REALM_SYNC_VERSION=4.4.2-ndk18.1 REALM_SYNC_SHA256= # Object Server Release used by Integration tests. Installed using NPM. From bb8ac2ace8ed0ed754bdebc77cb6378bb5bb8709 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 16 May 2019 16:25:07 +0200 Subject: [PATCH 09/47] Fix compiler error in OS --- realm/realm-library/src/main/cpp/object-store | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/realm/realm-library/src/main/cpp/object-store b/realm/realm-library/src/main/cpp/object-store index 7671d4de33..484952de9e 160000 --- a/realm/realm-library/src/main/cpp/object-store +++ b/realm/realm-library/src/main/cpp/object-store @@ -1 +1 @@ -Subproject commit 7671d4de33481b2bf7fb763522b5cb3bc889d981 +Subproject commit 484952de9e6a173d08961e7cca2e2d7dfbe1b117 From 5868d11619e4a20309fa558081e54e709c85900e Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 16 May 2019 16:25:27 +0200 Subject: [PATCH 10/47] Download proper version of NDK for Jenkins --- Dockerfile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 77fa0e1f09..8e80af420f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -67,13 +67,11 @@ RUN yes | sdkmanager \ # Install the NDK RUN mkdir /opt/android-ndk-tmp && \ cd /opt/android-ndk-tmp && \ - wget -q http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin -O android-ndk.bin && \ - chmod a+x ./android-ndk.bin && \ - ./android-ndk.bin && \ - mv android-ndk-r10e /opt/android-ndk && \ + wget -q https://dl.google.com/android/repository/android-ndk-r18b-linux-x86_64.zip -O android-ndk.zip && \ + unzip android-ndk.zip && \ + mv android-ndk-r18b /opt/android-ndk && \ rm -rf /opt/android-ndk-tmp && \ - chmod -R a+rX /opt/android-ndk && \ - echo "Pkg.Desc = Android NDK\nPkg.Revision = 10.0.0" > /opt/android-ndk/source.properties + chmod -R a+rX /opt/android-ndk # Make the SDK universally writable RUN chmod -R a+rwX ${ANDROID_HOME} From fdb6490c27cfb00599e1de3a7655d15ad7289e44 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 16 May 2019 16:30:38 +0200 Subject: [PATCH 11/47] Remove unused file --- realm.properties | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 realm.properties diff --git a/realm.properties b/realm.properties deleted file mode 100644 index f94385d28a..0000000000 --- a/realm.properties +++ /dev/null @@ -1,2 +0,0 @@ -gradleVersion=4.9 -ndkVersion=18.1.5063045 From a5e6ab51e3fc700491134790cbadf32661a2c8c9 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 16 May 2019 16:34:32 +0200 Subject: [PATCH 12/47] Cleanup --- realm/build.gradle | 1 - realm/realm-library/src/main/cpp/CMakeLists.txt | 2 -- 2 files changed, 3 deletions(-) diff --git a/realm/build.gradle b/realm/build.gradle index b71c540253..b05dad5930 100644 --- a/realm/build.gradle +++ b/realm/build.gradle @@ -34,7 +34,6 @@ allprojects { projectDependencies.each { key, val -> project.ext.set(key, val) } - // FIXME: Should be 16. Set to 21 currently due to OpenSSL project.ext.minSdkVersion = 16 project.ext.compileSdkVersion = 28 project.ext.buildToolsVersion = projectDependencies.get("ANDROID_BUILD_TOOLS") diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index 323d6cf27c..f335e72d7a 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -109,8 +109,6 @@ use_realm_core(${build_SYNC} "${REALM_CORE_DIST_DIR}" "${CORE_SOURCE_PATH}") set(openssl_build_TYPE "release") # FIXME Read the openssl version from core when the core/sync release has that information. set(openssl_VERSION "1.1.1b") -set(openssl_BUILD_NUMBER "1") -# set(openssl_FILENAME "openssl-${openssl_build_TYPE}-${openssl_VERSION}-${openssl_BUILD_NUMBER}-Android-${ANDROID_ABI}.tar.gz") set (openssl_FILENAME "openssl.tgz") set(openssl_URL "http://static.realm.io/downloads/openssl/${openssl_VERSION}/Android/${ANDROID_ABI}/${openssl_FILENAME}") From fac0a548a3f41c0c9e3367228b52a9beb66b7175 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 16 May 2019 17:19:05 +0200 Subject: [PATCH 13/47] Add debug information --- realm/realm-library/src/main/cpp/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index f335e72d7a..976da7f0d9 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -117,7 +117,7 @@ file(DOWNLOAD "${openssl_URL}" "${PROJECT_BINARY_DIR}/${openssl_FILENAME}") message(STATUS "Uncompressing OpenSSL...") execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_BINARY_DIR}/${openssl_FILENAME}" WORKING_DIRECTORY "${PROJECT_BINARY_DIR}") - +message(STATUS "Unzipped OpenSSL in ${PROJECT_BINARY_DIR}/${openssl_FILENAME}") message(STATUS "Importing OpenSSL...") include(${PROJECT_BINARY_DIR}/lib/cmake/openSSL/OpenSSLConfig.cmake) get_target_property(openssl_include_DIR OpenSSL::Crypto INTERFACE_INCLUDE_DIRECTORIES) From 5e9452a0bcf601001802bd3bf821195ea5f2da32 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 16 May 2019 17:26:35 +0200 Subject: [PATCH 14/47] More debug --- realm/realm-library/src/main/cpp/CMakeLists.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index 976da7f0d9..1990d1ada4 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -104,9 +104,7 @@ include(RealmCore) use_realm_core(${build_SYNC} "${REALM_CORE_DIST_DIR}" "${CORE_SOURCE_PATH}") -# Download openssl lib -#string(TOLOWER "${CMAKE_BUILD_TYPE}" openssl_build_TYPE) -set(openssl_build_TYPE "release") +# Download OpenSSL lib # FIXME Read the openssl version from core when the core/sync release has that information. set(openssl_VERSION "1.1.1b") set (openssl_FILENAME "openssl.tgz") @@ -119,6 +117,11 @@ message(STATUS "Uncompressing OpenSSL...") execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_BINARY_DIR}/${openssl_FILENAME}" WORKING_DIRECTORY "${PROJECT_BINARY_DIR}") message(STATUS "Unzipped OpenSSL in ${PROJECT_BINARY_DIR}/${openssl_FILENAME}") message(STATUS "Importing OpenSSL...") +if(EXISTS "${PROJECT_BINARY_DIR}/lib/cmake/openSSL/OpenSSLConfig.cmake") + message(STATUS "Found OpenSSL Cmake file") +else() + message(STATUS "WTF. We just unzipped it.") +endif() include(${PROJECT_BINARY_DIR}/lib/cmake/openSSL/OpenSSLConfig.cmake) get_target_property(openssl_include_DIR OpenSSL::Crypto INTERFACE_INCLUDE_DIRECTORIES) get_target_property(crypto_LIB OpenSSL::Crypto IMPORTED_LOCATION) From 4b67be5b988e82b95b573d001de1a4ec4030f30d Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 16 May 2019 17:34:36 +0200 Subject: [PATCH 15/47] Unzip in current directory --- realm/realm-library/src/main/cpp/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index 1990d1ada4..46aacb2c0e 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -114,7 +114,7 @@ message(STATUS "Downloading OpenSSL...") file(DOWNLOAD "${openssl_URL}" "${PROJECT_BINARY_DIR}/${openssl_FILENAME}") message(STATUS "Uncompressing OpenSSL...") -execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_BINARY_DIR}/${openssl_FILENAME}" WORKING_DIRECTORY "${PROJECT_BINARY_DIR}") +execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xvfz "${PROJECT_BINARY_DIR}/${openssl_FILENAME}" WORKING_DIRECTORY "${PROJECT_BINARY_DIR}") message(STATUS "Unzipped OpenSSL in ${PROJECT_BINARY_DIR}/${openssl_FILENAME}") message(STATUS "Importing OpenSSL...") if(EXISTS "${PROJECT_BINARY_DIR}/lib/cmake/openSSL/OpenSSLConfig.cmake") From b6db5a32fec21117c6b200d42f95f4629c6219ef Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 16 May 2019 17:58:16 +0200 Subject: [PATCH 16/47] I'm an idiot and Linux is case sensitive while MacOS is not. --- realm/realm-library/src/main/cpp/CMakeLists.txt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index 46aacb2c0e..1155420d50 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -107,7 +107,7 @@ use_realm_core(${build_SYNC} "${REALM_CORE_DIST_DIR}" "${CORE_SOURCE_PATH}") # Download OpenSSL lib # FIXME Read the openssl version from core when the core/sync release has that information. set(openssl_VERSION "1.1.1b") -set (openssl_FILENAME "openssl.tgz") +set(openssl_FILENAME "openssl.tgz") set(openssl_URL "http://static.realm.io/downloads/openssl/${openssl_VERSION}/Android/${ANDROID_ABI}/${openssl_FILENAME}") message(STATUS "Downloading OpenSSL...") @@ -115,14 +115,8 @@ file(DOWNLOAD "${openssl_URL}" "${PROJECT_BINARY_DIR}/${openssl_FILENAME}") message(STATUS "Uncompressing OpenSSL...") execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xvfz "${PROJECT_BINARY_DIR}/${openssl_FILENAME}" WORKING_DIRECTORY "${PROJECT_BINARY_DIR}") -message(STATUS "Unzipped OpenSSL in ${PROJECT_BINARY_DIR}/${openssl_FILENAME}") message(STATUS "Importing OpenSSL...") -if(EXISTS "${PROJECT_BINARY_DIR}/lib/cmake/openSSL/OpenSSLConfig.cmake") - message(STATUS "Found OpenSSL Cmake file") -else() - message(STATUS "WTF. We just unzipped it.") -endif() -include(${PROJECT_BINARY_DIR}/lib/cmake/openSSL/OpenSSLConfig.cmake) +include(${PROJECT_BINARY_DIR}/lib/cmake/OpenSSL/OpenSSLConfig.cmake) get_target_property(openssl_include_DIR OpenSSL::Crypto INTERFACE_INCLUDE_DIRECTORIES) get_target_property(crypto_LIB OpenSSL::Crypto IMPORTED_LOCATION) get_target_property(ssl_LIB OpenSSL::SSL IMPORTED_LOCATION) From 0627c4a62497ca911aee72a36c00372410958792 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 16 May 2019 18:13:26 +0200 Subject: [PATCH 17/47] Set minSdkVersion to 16 --- examples/architectureComponentsExample/build.gradle | 2 +- examples/build.gradle | 2 +- examples/multiprocessExample/build.gradle | 2 +- library-benchmarks/build.gradle | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/architectureComponentsExample/build.gradle b/examples/architectureComponentsExample/build.gradle index 9af0f5f9a3..ed5c02970e 100644 --- a/examples/architectureComponentsExample/build.gradle +++ b/examples/architectureComponentsExample/build.gradle @@ -19,7 +19,7 @@ android { defaultConfig { applicationId 'io.realm.examples.arch' targetSdkVersion rootProject.sdkVersion - minSdkVersion 15 + minSdkVersion rootProject.minSdkVersion versionCode 1 versionName "1.0" diff --git a/examples/build.gradle b/examples/build.gradle index 4b3907a7d9..0436277664 100644 --- a/examples/build.gradle +++ b/examples/build.gradle @@ -1,7 +1,7 @@ def projectDependencies = new Properties() projectDependencies.load(new FileInputStream("${rootDir}/../dependencies.list")) project.ext.sdkVersion = 27 -project.ext.minSdkVersion = 15 +project.ext.minSdkVersion = 16 project.ext.buildTools = projectDependencies.get("ANDROID_BUILD_TOOLS") // Don't cache SNAPSHOT (changing) dependencies. diff --git a/examples/multiprocessExample/build.gradle b/examples/multiprocessExample/build.gradle index 1a5d7ebf33..17818f3578 100644 --- a/examples/multiprocessExample/build.gradle +++ b/examples/multiprocessExample/build.gradle @@ -8,7 +8,7 @@ android { defaultConfig { applicationId "io.realm.examples.realmmultiprocessexample" targetSdkVersion rootProject.sdkVersion - minSdkVersion 15 + minSdkVersion rootProject.minSdkVersion versionCode 1 versionName "1.0" } diff --git a/library-benchmarks/build.gradle b/library-benchmarks/build.gradle index 287910c0e6..bb59ac1b39 100644 --- a/library-benchmarks/build.gradle +++ b/library-benchmarks/build.gradle @@ -29,7 +29,7 @@ android { buildToolsVersion "${project.ext.get("ANDROID_BUILD_TOOLS")}" defaultConfig { - minSdkVersion 15 + minSdkVersion 16 targetSdkVersion 27 versionCode 1 versionName "1.0" From 41c1e157a7f5df93720533a09c80e9afaf57650a Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Fri, 17 May 2019 01:02:37 +0200 Subject: [PATCH 18/47] Fix tests --- dependencies.list | 4 +- .../src/main/cpp/io_realm_SyncSession.cpp | 50 +++++++++---------- tools/sync_test_server/Dockerfile | 2 +- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/dependencies.list b/dependencies.list index 68c815ee9d..c9daa7e77f 100644 --- a/dependencies.list +++ b/dependencies.list @@ -1,11 +1,11 @@ # Realm Sync release used by Realm Java (This includes Realm Core) # https://github.com/realm/realm-sync/releases REALM_SYNC_VERSION=4.4.2-ndk18.1 -REALM_SYNC_SHA256= +REALM_SYNC_SHA256=34e3e06ca4bedfdfa7a6ce8027882cf098c659e8eef54901fc33a73bcc12f3c7 # Object Server Release used by Integration tests. Installed using NPM. # Use `npm view realm-object-server versions` to get a list of available versions. -REALM_OBJECT_SERVER_VERSION=3.21.0-rc1 +REALM_OBJECT_SERVER_VERSION=3.21.1 # Common Android settings across projects GRADLE_BUILD_TOOLS=3.3.2 diff --git a/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp b/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp index 62eb7e9837..568b66765f 100644 --- a/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp +++ b/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp @@ -161,19 +161,20 @@ JNIEXPORT jboolean JNICALL Java_io_realm_SyncSession_nativeWaitForDownloadComple "(ILjava/lang/Long;Ljava/lang/String;)V"); JavaGlobalRef java_session_object_ref(env, session_object); - // FIXME - std::function callback = [&java_session_object_ref, callback_id](std::error_code error) { - JNIEnv* env = JniUtils::get_env(true); - JavaLocalRef java_error_code; - JavaLocalRef java_error_message; - if (error != std::error_code{}) { - java_error_code = JavaLocalRef(env, JavaClassGlobalDef::new_long(env, error.value())); - java_error_message = JavaLocalRef(env, env->NewStringUTF(error.message().c_str())); - } - env->CallVoidMethod(java_session_object_ref.get(), java_notify_result_method, - callback_id, java_error_code.get(), java_error_message.get()); - }; - bool listener_registered = session->wait_for_download_completion(callback); + bool listener_registered = + session->wait_for_download_completion([session_ref = &java_session_object_ref, callback_id](std::error_code error) { + JNIEnv* env = JniUtils::get_env(true); + JavaLocalRef java_error_code; + JavaLocalRef java_error_message; + if (error != std::error_code{}) { + java_error_code = + JavaLocalRef(env, JavaClassGlobalDef::new_long(env, error.value())); + java_error_message = JavaLocalRef(env, env->NewStringUTF(error.message().c_str())); + } + env->CallVoidMethod(session_ref->get(), java_notify_result_method, + callback_id, java_error_code.get(), java_error_message.get()); + }); + return to_jbool(listener_registered); } } @@ -197,19 +198,18 @@ JNIEXPORT jboolean JNICALL Java_io_realm_SyncSession_nativeWaitForUploadCompleti "(ILjava/lang/Long;Ljava/lang/String;)V"); JavaGlobalRef java_session_object_ref(env, session_object); - // FIXME bool listener_registered = - session->wait_for_upload_completion([&java_session_object_ref, callback_id](std::error_code error) { - JNIEnv* env = JniUtils::get_env(true); - JavaLocalRef java_error_code; - JavaLocalRef java_error_message; - if (error != std::error_code{}) { - java_error_code = JavaLocalRef(env, JavaClassGlobalDef::new_long(env, error.value())); - java_error_message = JavaLocalRef(env, env->NewStringUTF(error.message().c_str())); - } - env->CallVoidMethod(java_session_object_ref.get(), java_notify_result_method, - callback_id, java_error_code.get(), java_error_message.get()); - }); + session->wait_for_upload_completion([session_ref = &java_session_object_ref, callback_id](std::error_code error) { + JNIEnv* env = JniUtils::get_env(true); + JavaLocalRef java_error_code; + JavaLocalRef java_error_message; + if (error != std::error_code{}) { + java_error_code = JavaLocalRef(env, JavaClassGlobalDef::new_long(env, error.value())); + java_error_message = JavaLocalRef(env, env->NewStringUTF(error.message().c_str())); + } + env->CallVoidMethod(session_ref->get(), java_notify_result_method, + callback_id, java_error_code.get(), java_error_message.get()); + }); return to_jbool(listener_registered); } diff --git a/tools/sync_test_server/Dockerfile b/tools/sync_test_server/Dockerfile index edcdc08940..19e38332cf 100644 --- a/tools/sync_test_server/Dockerfile +++ b/tools/sync_test_server/Dockerfile @@ -1,4 +1,4 @@ -FROM node:6.11.4 +FROM node:10.13 # set timezone to Copenhagen (by default it's using UTC) to match Android's device time. RUN cp /usr/share/zoneinfo/Europe/Copenhagen /etc/localtime From 44ff7c8063eb997870c78dbefe070f31663b8d71 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Fri, 17 May 2019 01:10:05 +0200 Subject: [PATCH 19/47] Cleanup and formatting --- CHANGELOG.md | 7 +-- .../src/main/cpp/io_realm_SyncSession.cpp | 46 +++++++++---------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52ea165b76..c885dd762c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ### Breaking Changes * Removed support for the MIPS CPU architecture. -* MinSdk has been raised from 9 to 16 +* MinSdk has been raised from 9 to 16. ### Enhancements * The native code is now built with `-fstack-protector-strong`. This has no security impact when using Realm Java, but some security tools only analyzed the C++ code and reported the missing flag as a security hole. [#4553](https://github.com/realm/realm-java/issues/4553) @@ -11,13 +11,14 @@ * None ### Compatibility -* Realm Object Server: 3.11.0 or later. +* Realm Object Server: 3.21.0 or later. * File format: Generates Realms with format v9 (Reads and upgrades all previous formats) * APIs are backwards compatible with all previous release of realm-java in the 6.x.y series. ### Internal * The NDK has been upgraded from NDK r10e to r18b. -* OpenSSL used by Realms encryption layer has been upgraded from 1.0.2k to 1.1.1a +* The compiler used for C++ code has changed from GCC to Clang. +* OpenSSL used by Realms encryption layer has been upgraded from 1.0.2k to 1.1.1b. ## 5.12.0(YYYY-MM-DD) diff --git a/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp b/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp index 568b66765f..6923c7aeb0 100644 --- a/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp +++ b/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp @@ -162,18 +162,18 @@ JNIEXPORT jboolean JNICALL Java_io_realm_SyncSession_nativeWaitForDownloadComple JavaGlobalRef java_session_object_ref(env, session_object); bool listener_registered = - session->wait_for_download_completion([session_ref = &java_session_object_ref, callback_id](std::error_code error) { - JNIEnv* env = JniUtils::get_env(true); - JavaLocalRef java_error_code; - JavaLocalRef java_error_message; - if (error != std::error_code{}) { - java_error_code = - JavaLocalRef(env, JavaClassGlobalDef::new_long(env, error.value())); - java_error_message = JavaLocalRef(env, env->NewStringUTF(error.message().c_str())); - } - env->CallVoidMethod(session_ref->get(), java_notify_result_method, - callback_id, java_error_code.get(), java_error_message.get()); - }); + session->wait_for_download_completion([session_ref = &java_session_object_ref, callback_id](std::error_code error) { + JNIEnv* env = JniUtils::get_env(true); + JavaLocalRef java_error_code; + JavaLocalRef java_error_message; + if (error != std::error_code{}) { + java_error_code = + JavaLocalRef(env, JavaClassGlobalDef::new_long(env, error.value())); + java_error_message = JavaLocalRef(env, env->NewStringUTF(error.message().c_str())); + } + env->CallVoidMethod(session_ref->get(), java_notify_result_method, + callback_id, java_error_code.get(), java_error_message.get()); + }); return to_jbool(listener_registered); } @@ -199,17 +199,17 @@ JNIEXPORT jboolean JNICALL Java_io_realm_SyncSession_nativeWaitForUploadCompleti JavaGlobalRef java_session_object_ref(env, session_object); bool listener_registered = - session->wait_for_upload_completion([session_ref = &java_session_object_ref, callback_id](std::error_code error) { - JNIEnv* env = JniUtils::get_env(true); - JavaLocalRef java_error_code; - JavaLocalRef java_error_message; - if (error != std::error_code{}) { - java_error_code = JavaLocalRef(env, JavaClassGlobalDef::new_long(env, error.value())); - java_error_message = JavaLocalRef(env, env->NewStringUTF(error.message().c_str())); - } - env->CallVoidMethod(session_ref->get(), java_notify_result_method, - callback_id, java_error_code.get(), java_error_message.get()); - }); + session->wait_for_upload_completion([session_ref = &java_session_object_ref, callback_id](std::error_code error) { + JNIEnv* env = JniUtils::get_env(true); + JavaLocalRef java_error_code; + JavaLocalRef java_error_message; + if (error != std::error_code{}) { + java_error_code = JavaLocalRef(env, JavaClassGlobalDef::new_long(env, error.value())); + java_error_message = JavaLocalRef(env, env->NewStringUTF(error.message().c_str())); + } + env->CallVoidMethod(session_ref->get(), java_notify_result_method, + callback_id, java_error_code.get(), java_error_message.get()); + }); return to_jbool(listener_registered); } From 79594f67f8017ab149d3eb90a26c8ea7fc46647e Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Fri, 17 May 2019 10:44:58 +0200 Subject: [PATCH 20/47] Optimize compiler/linker flags for size --- realm/realm-library/src/main/cpp/CMakeLists.txt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index 1155420d50..77797d6623 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -152,19 +152,20 @@ endif() # -Wno-missing-field-initializers disable in object store as well. set(WARNING_CXX_FLAGS "-Werror -Wall -Wextra -pedantic -Wmissing-declarations \ -Wempty-body -Wparentheses -Wunknown-pragmas -Wunreachable-code \ - -Wno-missing-field-initializers -Wno-uninitialized") + -Wno-missing-field-initializers") set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -pthread -fPIC -frtti -fvisibility=hidden -std=c++14 -fsigned-char") if (build_SYNC) set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ENABLE_SYNC=1") endif() -# There might be an issue with -Os of ndk gcc 4.9. It will hang the encryption related tests. -# And this issue doesn't seem to impact the core compiling. -set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") -#-ggdb doesn't play well with -flto +set(CMAKE_CXX_FLAGS_RELEASE "-O2 -ffunction-sections -fdata-sections -DNDEBUG") +# -ggdb doesn't play well with -flto set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -Og") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${REALM_COMMON_CXX_FLAGS} ${WARNING_CXX_FLAGS} ${ABI_CXX_FLAGS}") -# Set link flags +# Set Linker flags flags +if (CMAKE_BUILD_TYPE STREQUAL "Release") + set(REALM_LINKER_FLAGS "${REALM_LINKER_FLAGS} -dead_strip -flto") # LLD doesn't work yet +endif() if (build_SYNC) set(REALM_LINKER_FLAGS "${REALM_LINKER_FLAGS} -lz") endif() From a91fcca39ad089f9f89ef6eb2e9cec11a68ee004 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Sun, 19 May 2019 23:52:07 +0200 Subject: [PATCH 21/47] Attempt to optimize size --- realm/realm-library/build.gradle | 2 +- .../realm-library/src/main/cpp/CMakeLists.txt | 18 ++++-------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/realm/realm-library/build.gradle b/realm/realm-library/build.gradle index e070a90140..e1210701b2 100644 --- a/realm/realm-library/build.gradle +++ b/realm/realm-library/build.gradle @@ -59,7 +59,7 @@ android { if (project.hasProperty('buildTargetABIs') && !project.getProperty('buildTargetABIs').trim().isEmpty()) { abiFilters(*project.getProperty('buildTargetABIs').trim().split('\\s*,\\s*')) } else { - // armeabi and MIPS are no longer supported by the NDK + // "armeabi" and "mips" are no longer supported by the NDK abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a' } } diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index 77797d6623..6bfe81e72c 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -114,7 +114,7 @@ message(STATUS "Downloading OpenSSL...") file(DOWNLOAD "${openssl_URL}" "${PROJECT_BINARY_DIR}/${openssl_FILENAME}") message(STATUS "Uncompressing OpenSSL...") -execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xvfz "${PROJECT_BINARY_DIR}/${openssl_FILENAME}" WORKING_DIRECTORY "${PROJECT_BINARY_DIR}") +execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz "${PROJECT_BINARY_DIR}/${openssl_FILENAME}" WORKING_DIRECTORY "${PROJECT_BINARY_DIR}") message(STATUS "Importing OpenSSL...") include(${PROJECT_BINARY_DIR}/lib/cmake/OpenSSL/OpenSSLConfig.cmake) get_target_property(openssl_include_DIR OpenSSL::Crypto INTERFACE_INCLUDE_DIRECTORIES) @@ -127,16 +127,6 @@ include_directories( ${jni_headers_PATH} ${CMAKE_SOURCE_DIR}/object-store/src) -set(ANDROID_STL "c++_static") -set(ANDROID_NO_UNDEFINED OFF) -set(ANDROID_SO_UNDEFINED ON) - -if (ARMEABI) - set(ABI_CXX_FLAGS "-mthumb") -elseif (ARMEABI_V7A) - set(ABI_CXX_FLAGS "-mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16") -endif() - # Hack the memmove bug on Samsung device. if (ARMEABI OR ARMEABI_V7A) set(REALM_LINKER_FLAGS "${REALM_LINKER_FLAGS} -Wl,--wrap,memmove -Wl,--wrap,memcpy") @@ -153,18 +143,18 @@ endif() set(WARNING_CXX_FLAGS "-Werror -Wall -Wextra -pedantic -Wmissing-declarations \ -Wempty-body -Wparentheses -Wunknown-pragmas -Wunreachable-code \ -Wno-missing-field-initializers") -set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -pthread -fPIC -frtti -fvisibility=hidden -std=c++14 -fsigned-char") +set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -pthread -fpic -frtti -fvisibility=hidden -fvisibility-inlines-hidden -fsigned-char -std=c++14") if (build_SYNC) set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ENABLE_SYNC=1") endif() -set(CMAKE_CXX_FLAGS_RELEASE "-O2 -ffunction-sections -fdata-sections -DNDEBUG") +set(CMAKE_CXX_FLAGS_RELEASE "-Os -ffunction-sections -fdata-sections -fomit-frame-pointer -g0") # -ggdb doesn't play well with -flto set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -Og") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${REALM_COMMON_CXX_FLAGS} ${WARNING_CXX_FLAGS} ${ABI_CXX_FLAGS}") # Set Linker flags flags if (CMAKE_BUILD_TYPE STREQUAL "Release") - set(REALM_LINKER_FLAGS "${REALM_LINKER_FLAGS} -dead_strip -flto") # LLD doesn't work yet + set(REALM_LINKER_FLAGS "${REALM_LINKER_FLAGS} -Wl,--gc-sections -Wl,--icf=safe") endif() if (build_SYNC) set(REALM_LINKER_FLAGS "${REALM_LINKER_FLAGS} -lz") From 911c16443ec58b4727e8825acae9c2fd3d6474b2 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Mon, 20 May 2019 00:03:19 +0200 Subject: [PATCH 22/47] More minimizations --- realm/realm-library/src/main/cpp/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index 6bfe81e72c..30bafc4b92 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -147,14 +147,14 @@ set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HA if (build_SYNC) set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ENABLE_SYNC=1") endif() -set(CMAKE_CXX_FLAGS_RELEASE "-Os -ffunction-sections -fdata-sections -fomit-frame-pointer -g0") +set(CMAKE_CXX_FLAGS_RELEASE "-Oz -ffunction-sections -fdata-sections -fomit-frame-pointer -g0") # -ggdb doesn't play well with -flto set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -Og") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${REALM_COMMON_CXX_FLAGS} ${WARNING_CXX_FLAGS} ${ABI_CXX_FLAGS}") # Set Linker flags flags if (CMAKE_BUILD_TYPE STREQUAL "Release") - set(REALM_LINKER_FLAGS "${REALM_LINKER_FLAGS} -Wl,--gc-sections -Wl,--icf=safe") + set(REALM_LINKER_FLAGS "${REALM_LINKER_FLAGS} -Wl,--gc-sections") endif() if (build_SYNC) set(REALM_LINKER_FLAGS "${REALM_LINKER_FLAGS} -lz") From 533e47d64662945623ae2346e62028c0b0f74cd6 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Tue, 21 May 2019 16:41:44 +0200 Subject: [PATCH 23/47] Optimize flags for size --- realm/realm-library/src/main/cpp/CMakeLists.txt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index 30bafc4b92..c4daf010a0 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -101,7 +101,6 @@ create_javah(TARGET jni_headers ) include(RealmCore) - use_realm_core(${build_SYNC} "${REALM_CORE_DIST_DIR}" "${CORE_SOURCE_PATH}") # Download OpenSSL lib @@ -143,18 +142,18 @@ endif() set(WARNING_CXX_FLAGS "-Werror -Wall -Wextra -pedantic -Wmissing-declarations \ -Wempty-body -Wparentheses -Wunknown-pragmas -Wunreachable-code \ -Wno-missing-field-initializers") -set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -pthread -fpic -frtti -fvisibility=hidden -fvisibility-inlines-hidden -fsigned-char -std=c++14") +set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DNDEBUG -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -fdata-sections -pthread -frtti -fvisibility=hidden -fvisibility-inlines-hidden -fsigned-char -std=c++14") if (build_SYNC) set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ENABLE_SYNC=1") endif() -set(CMAKE_CXX_FLAGS_RELEASE "-Oz -ffunction-sections -fdata-sections -fomit-frame-pointer -g0") +set(CMAKE_CXX_FLAGS_RELEASE "-Oz") # -ggdb doesn't play well with -flto set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -Og") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${REALM_COMMON_CXX_FLAGS} ${WARNING_CXX_FLAGS} ${ABI_CXX_FLAGS}") # Set Linker flags flags if (CMAKE_BUILD_TYPE STREQUAL "Release") - set(REALM_LINKER_FLAGS "${REALM_LINKER_FLAGS} -Wl,--gc-sections") + set(REALM_LINKER_FLAGS "${REALM_LINKER_FLAGS} -Wl,-gc-sections") endif() if (build_SYNC) set(REALM_LINKER_FLAGS "${REALM_LINKER_FLAGS} -lz") From 945094d70a3a549f8e5280093d4c601b63ff7fb1 Mon Sep 17 00:00:00 2001 From: Nabil Hachicha Date: Thu, 30 May 2019 08:50:22 +0100 Subject: [PATCH 24/47] update debug/release flag --- realm/realm-library/build.gradle | 2 +- realm/realm-library/src/main/cpp/CMakeLists.txt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/realm/realm-library/build.gradle b/realm/realm-library/build.gradle index e1210701b2..e50fecc531 100644 --- a/realm/realm-library/build.gradle +++ b/realm/realm-library/build.gradle @@ -37,7 +37,7 @@ ext.coreDir = file(project.coreSourcePath ? ext.ccachePath = project.findProperty('ccachePath') ?: System.getenv('NDK_CCACHE') ext.lcachePath = project.findProperty('lcachePath') ?: System.getenv('NDK_LCACHE') // Set to true to enable linking with debug core. -ext.enableDebugCore = project.hasProperty('enableDebugCore') ? project.getProperty('enableDebugCore') : false //FIXME Use 'false' as default until https://github.com/realm/realm-java/issues/5354 is fixed +ext.enableDebugCore = project.hasProperty('enableDebugCore') ? project.getProperty('enableDebugCore') : true android { compileSdkVersion rootProject.compileSdkVersion diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index c4daf010a0..96f4c28d77 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -107,7 +107,7 @@ use_realm_core(${build_SYNC} "${REALM_CORE_DIST_DIR}" "${CORE_SOURCE_PATH}") # FIXME Read the openssl version from core when the core/sync release has that information. set(openssl_VERSION "1.1.1b") set(openssl_FILENAME "openssl.tgz") -set(openssl_URL "http://static.realm.io/downloads/openssl/${openssl_VERSION}/Android/${ANDROID_ABI}/${openssl_FILENAME}") +set(openssl_URL "https://static.realm.io/downloads/openssl/${openssl_VERSION}/Android/${ANDROID_ABI}/${openssl_FILENAME}") message(STATUS "Downloading OpenSSL...") file(DOWNLOAD "${openssl_URL}" "${PROJECT_BINARY_DIR}/${openssl_FILENAME}") @@ -142,11 +142,11 @@ endif() set(WARNING_CXX_FLAGS "-Werror -Wall -Wextra -pedantic -Wmissing-declarations \ -Wempty-body -Wparentheses -Wunknown-pragmas -Wunreachable-code \ -Wno-missing-field-initializers") -set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DNDEBUG -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -fdata-sections -pthread -frtti -fvisibility=hidden -fvisibility-inlines-hidden -fsigned-char -std=c++14") +set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -fdata-sections -pthread -frtti -fvisibility=hidden -fvisibility-inlines-hidden -fsigned-char -std=c++14") if (build_SYNC) set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ENABLE_SYNC=1") endif() -set(CMAKE_CXX_FLAGS_RELEASE "-Oz") +set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -Oz") # -ggdb doesn't play well with -flto set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -Og") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${REALM_COMMON_CXX_FLAGS} ${WARNING_CXX_FLAGS} ${ABI_CXX_FLAGS}") From 816be063f40e6f2ce5459ea1e56094787f70b818 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Tue, 11 Feb 2020 09:33:05 +0100 Subject: [PATCH 25/47] Use proper NDK on CI --- Dockerfile | 4 ++-- realm/realm-library/build.gradle | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8e80af420f..e41a62a059 100644 --- a/Dockerfile +++ b/Dockerfile @@ -67,9 +67,9 @@ RUN yes | sdkmanager \ # Install the NDK RUN mkdir /opt/android-ndk-tmp && \ cd /opt/android-ndk-tmp && \ - wget -q https://dl.google.com/android/repository/android-ndk-r18b-linux-x86_64.zip -O android-ndk.zip && \ + wget -q https://dl.google.com/android/repository/android-ndk-r21-linux-x86_64.zip -O android-ndk.zip && \ unzip android-ndk.zip && \ - mv android-ndk-r18b /opt/android-ndk && \ + mv android-ndk-r21 /opt/android-ndk && \ rm -rf /opt/android-ndk-tmp && \ chmod -R a+rX /opt/android-ndk diff --git a/realm/realm-library/build.gradle b/realm/realm-library/build.gradle index c174c9a17e..bc289641a1 100644 --- a/realm/realm-library/build.gradle +++ b/realm/realm-library/build.gradle @@ -793,7 +793,7 @@ def checkNdk(String ndkPath) { } if (detectedNdkVersion != project.ndkVersion) { throw new GradleException("Your NDK version: ${detectedNdkVersion}." - + " Realm JNI must be compiled with the version ${project.ndkVersion} of NDK.") + + " Realm JNI must be compiled with version ${project.ndkVersion} of the NDK.") } } From 465780c38015d2c7dd0dba7ca7feb533b894dffd Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Tue, 11 Feb 2020 10:18:53 +0100 Subject: [PATCH 26/47] Attempt to fix warning on Linux --- realm/realm-library/src/main/cpp/jni_util/jni_utils.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/realm/realm-library/src/main/cpp/jni_util/jni_utils.cpp b/realm/realm-library/src/main/cpp/jni_util/jni_utils.cpp index 0ca6f526a3..94d3f81ce3 100644 --- a/realm/realm-library/src/main/cpp/jni_util/jni_utils.cpp +++ b/realm/realm-library/src/main/cpp/jni_util/jni_utils.cpp @@ -48,7 +48,10 @@ JNIEnv* JniUtils::get_env(bool attach_if_needed) REALM_ASSERT_RELEASE(ret == JNI_OK); } else { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunreachable-code" REALM_ASSERT_RELEASE(false); +#pragma clang diagnostic pop } } From a2311143c0fd189ad46b507cde1ee1e93604d382 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 13 Feb 2020 15:58:32 +0100 Subject: [PATCH 27/47] Update OS branch --- realm/realm-library/src/main/cpp/object-store | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/realm/realm-library/src/main/cpp/object-store b/realm/realm-library/src/main/cpp/object-store index 6ca7421e98..64c8821912 160000 --- a/realm/realm-library/src/main/cpp/object-store +++ b/realm/realm-library/src/main/cpp/object-store @@ -1 +1 @@ -Subproject commit 6ca7421e988fecef9662c07fc0973c4836cf3ebf +Subproject commit 64c88219128b42fe831a6cadac1ac3a3893f668b From b760983defa7951c3768336f4ef77a2c8ae93f3d Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 13 Feb 2020 17:09:47 +0100 Subject: [PATCH 28/47] Bump to latest OS --- realm/realm-library/src/main/cpp/object-store | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/realm/realm-library/src/main/cpp/object-store b/realm/realm-library/src/main/cpp/object-store index 64c8821912..e96d41a960 160000 --- a/realm/realm-library/src/main/cpp/object-store +++ b/realm/realm-library/src/main/cpp/object-store @@ -1 +1 @@ -Subproject commit 64c88219128b42fe831a6cadac1ac3a3893f668b +Subproject commit e96d41a960b778a041f53a6d1373be0885a4352e From f63f7ef4c847cd1a1ed4c4cbd38dce4a5ef0c725 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 13 Feb 2020 18:55:18 +0100 Subject: [PATCH 29/47] Update OS --- realm/realm-library/src/main/cpp/object-store | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/realm/realm-library/src/main/cpp/object-store b/realm/realm-library/src/main/cpp/object-store index e96d41a960..d140082a5f 160000 --- a/realm/realm-library/src/main/cpp/object-store +++ b/realm/realm-library/src/main/cpp/object-store @@ -1 +1 @@ -Subproject commit e96d41a960b778a041f53a6d1373be0885a4352e +Subproject commit d140082a5fda0b573cf99e8c9c1aff1e169bf3a5 From 527351680f53678d4bcfc085055672c35be25151 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 13 Feb 2020 19:44:58 +0100 Subject: [PATCH 30/47] Update OS --- realm/realm-library/src/main/cpp/object-store | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/realm/realm-library/src/main/cpp/object-store b/realm/realm-library/src/main/cpp/object-store index d140082a5f..66199adbff 160000 --- a/realm/realm-library/src/main/cpp/object-store +++ b/realm/realm-library/src/main/cpp/object-store @@ -1 +1 @@ -Subproject commit d140082a5fda0b573cf99e8c9c1aff1e169bf3a5 +Subproject commit 66199adbfffbe153e696309a53d4ec03e32c44e3 From 3a42f0b10fdc28785da67bc1e1d3e6661580fb76 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 13 Feb 2020 19:52:21 +0100 Subject: [PATCH 31/47] Disable unevaluated-expression --- realm/realm-library/src/main/cpp/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index 00c350a733..2836d9df9c 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -141,7 +141,7 @@ endif() # -Wno-missing-field-initializers disable in object store as well. set(WARNING_CXX_FLAGS "-Werror -Wall -Wextra -pedantic -Wmissing-declarations \ -Wempty-body -Wparentheses -Wunknown-pragmas -Wunreachable-code \ - -Wno-missing-field-initializers") + -Wno-missing-field-initializers -Wno-unevaluated-expression") set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -fdata-sections -pthread -frtti -fvisibility=hidden -fvisibility-inlines-hidden -fsigned-char -std=c++14") if (build_SYNC) set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ENABLE_SYNC=1") From e09c8557724c2fd19682581bc54669327da2fd61 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Tue, 18 Feb 2020 21:08:53 +0100 Subject: [PATCH 32/47] Disable more checks --- realm/realm-library/src/main/cpp/CMakeLists.txt | 4 ++-- realm/realm-library/src/main/cpp/jni_util/jni_utils.cpp | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index 2836d9df9c..07f6a3e636 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -15,7 +15,7 @@ # limitations under the License. # ########################################################################### -cmake_minimum_required(VERSION 3.6.0) +cmake_minimum_required(VERSION 3.15.0) FUNCTION(capitalizeFirstLetter var value) string(SUBSTRING ${value} 0 1 firstLetter) @@ -141,7 +141,7 @@ endif() # -Wno-missing-field-initializers disable in object store as well. set(WARNING_CXX_FLAGS "-Werror -Wall -Wextra -pedantic -Wmissing-declarations \ -Wempty-body -Wparentheses -Wunknown-pragmas -Wunreachable-code \ - -Wno-missing-field-initializers -Wno-unevaluated-expression") + -Wno-missing-field-initializers -Wno-unevaluated-expression --Wno-unreachable-code") set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -fdata-sections -pthread -frtti -fvisibility=hidden -fvisibility-inlines-hidden -fsigned-char -std=c++14") if (build_SYNC) set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ENABLE_SYNC=1") diff --git a/realm/realm-library/src/main/cpp/jni_util/jni_utils.cpp b/realm/realm-library/src/main/cpp/jni_util/jni_utils.cpp index 94d3f81ce3..0ca6f526a3 100644 --- a/realm/realm-library/src/main/cpp/jni_util/jni_utils.cpp +++ b/realm/realm-library/src/main/cpp/jni_util/jni_utils.cpp @@ -48,10 +48,7 @@ JNIEnv* JniUtils::get_env(bool attach_if_needed) REALM_ASSERT_RELEASE(ret == JNI_OK); } else { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunreachable-code" REALM_ASSERT_RELEASE(false); -#pragma clang diagnostic pop } } From d1832a028bb54619fce856f897256bc048675426 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Tue, 18 Feb 2020 23:10:12 +0100 Subject: [PATCH 33/47] Don't use JavaGlobalRef in lambda capture --- realm/realm-library/src/main/cpp/CMakeLists.txt | 2 +- .../src/main/cpp/io_realm_SyncSession.cpp | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index 07f6a3e636..21c402414e 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -141,7 +141,7 @@ endif() # -Wno-missing-field-initializers disable in object store as well. set(WARNING_CXX_FLAGS "-Werror -Wall -Wextra -pedantic -Wmissing-declarations \ -Wempty-body -Wparentheses -Wunknown-pragmas -Wunreachable-code \ - -Wno-missing-field-initializers -Wno-unevaluated-expression --Wno-unreachable-code") + -Wno-missing-field-initializers -Wno-unevaluated-expression") set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -fdata-sections -pthread -frtti -fvisibility=hidden -fvisibility-inlines-hidden -fsigned-char -std=c++14") if (build_SYNC) set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ENABLE_SYNC=1") diff --git a/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp b/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp index a4c83e6bfe..116ae319b2 100644 --- a/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp +++ b/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp @@ -157,8 +157,9 @@ JNIEXPORT jboolean JNICALL Java_io_realm_SyncSession_nativeWaitForDownloadComple static JavaClass java_sync_session_class(env, "io/realm/SyncSession"); static JavaMethod java_notify_result_method(env, java_sync_session_class, "notifyAllChangesSent", "(ILjava/lang/Long;Ljava/lang/String;)V"); - JavaGlobalRef java_session_object_ref(env, session_object); - session->wait_for_download_completion([&](std::error_code error) { +// JavaGlobalRef java_session_object_ref(env, session_object); + auto obj = env->NewGlobalRef(session_object); + session->wait_for_download_completion([obj, callback_id](std::error_code error) { JNIEnv* env = JniUtils::get_env(true); JavaLocalRef java_error_code; JavaLocalRef java_error_message; @@ -167,8 +168,9 @@ JNIEXPORT jboolean JNICALL Java_io_realm_SyncSession_nativeWaitForDownloadComple JavaLocalRef(env, JavaClassGlobalDef::new_long(env, error.value())); java_error_message = JavaLocalRef(env, env->NewStringUTF(error.message().c_str())); } - env->CallVoidMethod(java_session_object_ref.get(), java_notify_result_method, + env->CallVoidMethod(obj, java_notify_result_method, callback_id, java_error_code.get(), java_error_message.get()); + env->DeleteGlobalRef(obj); }); return to_jbool(JNI_TRUE); } @@ -190,9 +192,9 @@ JNIEXPORT jboolean JNICALL Java_io_realm_SyncSession_nativeWaitForUploadCompleti static JavaClass java_sync_session_class(env, "io/realm/SyncSession"); static JavaMethod java_notify_result_method(env, java_sync_session_class, "notifyAllChangesSent", "(ILjava/lang/Long;Ljava/lang/String;)V"); - JavaGlobalRef java_session_object_ref(env, session_object); - - session->wait_for_upload_completion([&](std::error_code error) { +// JavaGlobalRef java_session_object_ref(env, session_object); + auto obj = env->NewGlobalRef(session_object); + session->wait_for_upload_completion([obj, callback_id] (std::error_code error) { JNIEnv* env = JniUtils::get_env(true); JavaLocalRef java_error_code; JavaLocalRef java_error_message; @@ -200,8 +202,9 @@ JNIEXPORT jboolean JNICALL Java_io_realm_SyncSession_nativeWaitForUploadCompleti java_error_code = JavaLocalRef(env, JavaClassGlobalDef::new_long(env, error.value())); java_error_message = JavaLocalRef(env, env->NewStringUTF(error.message().c_str())); } - env->CallVoidMethod(java_session_object_ref.get(), java_notify_result_method, + env->CallVoidMethod(obj, java_notify_result_method, callback_id, java_error_code.get(), java_error_message.get()); + env->DeleteGlobalRef(obj); }); return JNI_TRUE; } From ef3862cfa652a3ae1b6a43286c694892dbc41868 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Tue, 18 Feb 2020 23:13:02 +0100 Subject: [PATCH 34/47] Reduce CMake version --- realm/realm-library/src/main/cpp/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index 21c402414e..2836d9df9c 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -15,7 +15,7 @@ # limitations under the License. # ########################################################################### -cmake_minimum_required(VERSION 3.15.0) +cmake_minimum_required(VERSION 3.6.0) FUNCTION(capitalizeFirstLetter var value) string(SUBSTRING ${value} 0 1 firstLetter) From a017c05936904e4d3f4dbf9771439b7f5f0b6459 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Tue, 18 Feb 2020 23:15:39 +0100 Subject: [PATCH 35/47] Disable more checks --- realm/realm-library/src/main/cpp/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index 2836d9df9c..9deb509f21 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -141,7 +141,7 @@ endif() # -Wno-missing-field-initializers disable in object store as well. set(WARNING_CXX_FLAGS "-Werror -Wall -Wextra -pedantic -Wmissing-declarations \ -Wempty-body -Wparentheses -Wunknown-pragmas -Wunreachable-code \ - -Wno-missing-field-initializers -Wno-unevaluated-expression") + -Wno-missing-field-initializers -Wno-unevaluated-expression -Wno-unreachable-code") set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -fdata-sections -pthread -frtti -fvisibility=hidden -fvisibility-inlines-hidden -fsigned-char -std=c++14") if (build_SYNC) set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ENABLE_SYNC=1") From 206427f58765f7962938dd44c50d2154f0c5f015 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Tue, 18 Feb 2020 23:50:23 +0100 Subject: [PATCH 36/47] Remove test --- .../java/io/realm/SyncConfigurationTests.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncConfigurationTests.java b/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncConfigurationTests.java index b39e6b7dad..9d5bc9e789 100644 --- a/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncConfigurationTests.java +++ b/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncConfigurationTests.java @@ -483,17 +483,6 @@ public void getDefaultConfiguration_isFullySynchronized() { SyncConfiguration config = user.getDefaultConfiguration(); } - @Test - public void automatic_isFullySynchronized() { - SyncUser user = SyncTestUtils.createTestUser(); - - SyncConfiguration config = SyncConfiguration.automatic(); - assertFalse(config.isFullySynchronizedRealm()); - - config = SyncConfiguration.automatic(user); - assertFalse(config.isFullySynchronizedRealm()); - } - @Test public void automatic_convertsAuthUrl() { Object[][] input = { From 522225cf26503b967c7d149b7e8c48943a238d1d Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Wed, 19 Feb 2020 00:16:37 +0100 Subject: [PATCH 37/47] Fix test --- .../main/java/io/realm/internal/sync/PermissionHelper.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/realm/realm-library/src/main/java/io/realm/internal/sync/PermissionHelper.java b/realm/realm-library/src/main/java/io/realm/internal/sync/PermissionHelper.java index 880d28439e..d19f7b6ff7 100644 --- a/realm/realm-library/src/main/java/io/realm/internal/sync/PermissionHelper.java +++ b/realm/realm-library/src/main/java/io/realm/internal/sync/PermissionHelper.java @@ -38,6 +38,9 @@ public class PermissionHelper { * @return */ public static Permission findOrCreatePermissionForRole(RealmObject container, RealmList permissions, String roleName) { + if (roleName == null) { + throw new IllegalArgumentException("Non-null 'roleName' required."); + } if (!container.isManaged()) { throw new IllegalStateException("'findOrCreate()' can only be called on managed objects."); } @@ -49,7 +52,6 @@ public static Permission findOrCreatePermissionForRole(RealmObject container, Re // Find existing permission object or create new one Permission permission = permissions.where().equalTo("role.name", roleName).findFirst(); if (permission == null) { - // Find existing role or create new one Role role = realm.where(Role.class).equalTo("name", roleName).findFirst(); if (role == null) { From 465fe9bef0afa9d4d2f73cfe867bb4e618df90e0 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Wed, 19 Feb 2020 10:38:33 +0100 Subject: [PATCH 38/47] Cleanup. Disable broken test. Fix JSON tests --- .../java/io/realm/RealmResultsTests.java | 88 +++++++++---------- .../src/main/cpp/io_realm_SyncSession.cpp | 2 - .../objectserver/ProgressListenerTests.java | 2 + 3 files changed, 42 insertions(+), 50 deletions(-) diff --git a/realm/realm-library/src/androidTest/java/io/realm/RealmResultsTests.java b/realm/realm-library/src/androidTest/java/io/realm/RealmResultsTests.java index 2bbe758dce..30bc219ed6 100644 --- a/realm/realm-library/src/androidTest/java/io/realm/RealmResultsTests.java +++ b/realm/realm-library/src/androidTest/java/io/realm/RealmResultsTests.java @@ -1774,18 +1774,16 @@ public void asJSON() throws JSONException { " \"columnDate\": \"" + now + "\",\n" + " \"columnBinary\": \"AQID\",\n" + " \"columnMutableRealmInteger\": 0,\n" + - " \"columnRealmObject\": [\n" + - " {\n" + - " \"_key\": 100,\n" + - " \"name\": \"dog1\",\n" + - " \"age\": 1,\n" + - " \"height\": 1.1,\n" + - " \"weight\": 10.100000381469727,\n" + - " \"hasTail\": true,\n" + - " \"birthday\": \"" + now + "\",\n" + - " \"owner\": null\n" + - " }\n" + - " ],\n" + + " \"columnRealmObject\": {\n" + + " \"_key\": 100,\n" + + " \"name\": \"dog1\",\n" + + " \"age\": 1,\n" + + " \"height\": 1.1,\n" + + " \"weight\": 10.100000381469727,\n" + + " \"hasTail\": true,\n" + + " \"birthday\": \"" + now + "\",\n" + + " \"owner\": null\n" + + " },\n" + " \"columnRealmList\": [\n" + " {\n" + " \"_key\": 101,\n" + @@ -1805,14 +1803,12 @@ public void asJSON() throws JSONException { " \"weight\": 30.100000381469727,\n" + " \"hasTail\": true,\n" + " \"birthday\": \"" + now + "\",\n" + - " \"owner\": [\n" + - " {\n" + - " \"_key\": 0,\n" + - " \"name\": \"Dog owner 1\",\n" + - " \"dogs\": [],\n" + - " \"cat\": null\n" + - " }\n" + - " ]\n" + + " \"owner\": {\n" + + " \"_key\": 0,\n" + + " \"name\": \"Dog owner 1\",\n" + + " \"dogs\": [],\n" + + " \"cat\": null\n" + + " }\n" + " }\n" + " ],\n" + " \"columnStringList\": [\n" + @@ -1876,20 +1872,18 @@ public void asJSON_cycles() throws JSONException { " \"id\": 0,\n" + " \"name\": \"One\",\n" + " \"date\": \"" + now + "\",\n" + - " \"object\": [\n" + - " {\n" + - " \"_key\": 1,\n" + - " \"id\": 0,\n" + - " \"name\": \"Two\",\n" + - " \"date\": \"" + now + "\",\n" + - " \"object\": {\n" + - " \"table\": \"class_CyclicType\",\n" + - " \"key\": 0\n" + - " },\n" + - " \"otherObject\": null,\n" + - " \"objects\": []\n" + - " }\n" + - " ],\n" + + " \"object\": {\n" + + " \"_key\": 1,\n" + + " \"id\": 0,\n" + + " \"name\": \"Two\",\n" + + " \"date\": \"" + now + "\",\n" + + " \"object\": {\n" + + " \"table\": \"class_CyclicType\",\n" + + " \"key\": 0\n" + + " },\n" + + " \"otherObject\": null,\n" + + " \"objects\": []\n" + + " },\n" + " \"otherObject\": null,\n" + " \"objects\": []\n" + " },\n" + @@ -1898,20 +1892,18 @@ public void asJSON_cycles() throws JSONException { " \"id\": 0,\n" + " \"name\": \"Two\",\n" + " \"date\": \"" + now + "\",\n" + - " \"object\": [\n" + - " {\n" + - " \"_key\": 0,\n" + - " \"id\": 0,\n" + - " \"name\": \"One\",\n" + - " \"date\": \"" + now + "\",\n" + - " \"object\": {\n" + - " \"table\": \"class_CyclicType\",\n" + - " \"key\": 1\n" + - " },\n" + - " \"otherObject\": null,\n" + - " \"objects\": []\n" + - " }\n" + - " ],\n" + + " \"object\": {\n" + + " \"_key\": 0,\n" + + " \"id\": 0,\n" + + " \"name\": \"One\",\n" + + " \"date\": \"" + now + "\",\n" + + " \"object\": {\n" + + " \"table\": \"class_CyclicType\",\n" + + " \"key\": 1\n" + + " },\n" + + " \"otherObject\": null,\n" + + " \"objects\": []\n" + + " },\n" + " \"otherObject\": null,\n" + " \"objects\": []\n" + " }\n" + diff --git a/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp b/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp index 116ae319b2..40da63f010 100644 --- a/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp +++ b/realm/realm-library/src/main/cpp/io_realm_SyncSession.cpp @@ -157,7 +157,6 @@ JNIEXPORT jboolean JNICALL Java_io_realm_SyncSession_nativeWaitForDownloadComple static JavaClass java_sync_session_class(env, "io/realm/SyncSession"); static JavaMethod java_notify_result_method(env, java_sync_session_class, "notifyAllChangesSent", "(ILjava/lang/Long;Ljava/lang/String;)V"); -// JavaGlobalRef java_session_object_ref(env, session_object); auto obj = env->NewGlobalRef(session_object); session->wait_for_download_completion([obj, callback_id](std::error_code error) { JNIEnv* env = JniUtils::get_env(true); @@ -192,7 +191,6 @@ JNIEXPORT jboolean JNICALL Java_io_realm_SyncSession_nativeWaitForUploadCompleti static JavaClass java_sync_session_class(env, "io/realm/SyncSession"); static JavaMethod java_notify_result_method(env, java_sync_session_class, "notifyAllChangesSent", "(ILjava/lang/Long;Ljava/lang/String;)V"); -// JavaGlobalRef java_session_object_ref(env, session_object); auto obj = env->NewGlobalRef(session_object); session->wait_for_upload_completion([obj, callback_id] (std::error_code error) { JNIEnv* env = JniUtils::get_env(true); diff --git a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java index 228a5f08e1..6e7c1bc80a 100644 --- a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java +++ b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java @@ -18,6 +18,7 @@ import android.support.test.runner.AndroidJUnit4; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -132,6 +133,7 @@ private long getStoreTestDataSize(RealmConfiguration config) { return objectCounts; } + @Ignore("FIXME: See https://mongodb.slack.com/archives/CL7EWAHCY/p1582101560005200") @Test public void downloadProgressListener_changesOnly() { final CountDownLatch allChangesDownloaded = new CountDownLatch(1); From 829f30692ad1f68e866d160853410c4356861802 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Wed, 19 Feb 2020 11:44:42 +0100 Subject: [PATCH 39/47] Disable correct test --- .../java/io/realm/SyncConfigurationTests.java | 1 + .../java/io/realm/objectserver/ProgressListenerTests.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncConfigurationTests.java b/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncConfigurationTests.java index 9d5bc9e789..4c3fccc2c8 100644 --- a/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncConfigurationTests.java +++ b/realm/realm-library/src/androidTestObjectServer/java/io/realm/SyncConfigurationTests.java @@ -481,6 +481,7 @@ public void getDefaultConfiguration_throwsIfNotLoggedIn() { public void getDefaultConfiguration_isFullySynchronized() { SyncUser user = createTestUser(); SyncConfiguration config = user.getDefaultConfiguration(); + assertFalse(config.isFullySynchronizedRealm()); } @Test diff --git a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java index 6e7c1bc80a..948210f4c4 100644 --- a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java +++ b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java @@ -133,7 +133,6 @@ private long getStoreTestDataSize(RealmConfiguration config) { return objectCounts; } - @Ignore("FIXME: See https://mongodb.slack.com/archives/CL7EWAHCY/p1582101560005200") @Test public void downloadProgressListener_changesOnly() { final CountDownLatch allChangesDownloaded = new CountDownLatch(1); @@ -267,6 +266,7 @@ public void onChange(Progress progress) { realm.close(); } + @Ignore("FIXME: See https://mongodb.slack.com/archives/CL7EWAHCY/p1582101560005200") @Test public void uploadProgressListener_changesOnly() { final CountDownLatch allChangeUploaded = new CountDownLatch(1); From 4225b3d65d6fce1149c9299d74252c93eddaefb9 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 20 Feb 2020 14:45:23 +0100 Subject: [PATCH 40/47] Temp disable all Progress listener tests f --- .../java/io/realm/objectserver/ProgressListenerTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java index 948210f4c4..45bb770a4b 100644 --- a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java +++ b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java @@ -42,16 +42,17 @@ import io.realm.SyncSession; import io.realm.SyncUser; import io.realm.TestHelper; +import io.realm.TestSyncConfigurationFactory; import io.realm.entities.AllTypes; import io.realm.log.RealmLog; import io.realm.objectserver.utils.Constants; import io.realm.objectserver.utils.UserFactory; -import io.realm.TestSyncConfigurationFactory; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +@Ignore("FIXME: Most of these are currently broken. See https://mongodb.slack.com/archives/CL7EWAHCY/p1582101560005200") @RunWith(AndroidJUnit4.class) public class ProgressListenerTests extends StandardIntegrationTest { @@ -266,7 +267,6 @@ public void onChange(Progress progress) { realm.close(); } - @Ignore("FIXME: See https://mongodb.slack.com/archives/CL7EWAHCY/p1582101560005200") @Test public void uploadProgressListener_changesOnly() { final CountDownLatch allChangeUploaded = new CountDownLatch(1); From f1569985f977da0188c5cc641ebd19102b1bab6e Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Thu, 20 Feb 2020 21:54:29 +0100 Subject: [PATCH 41/47] Add helper script for finding size of library --- tools/print_library_size.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 tools/print_library_size.sh diff --git a/tools/print_library_size.sh b/tools/print_library_size.sh new file mode 100755 index 0000000000..fee8830cb3 --- /dev/null +++ b/tools/print_library_size.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +# This script will print the size of the Realm libraries. +# To run it: +# 1. Make sure that $D8 is defined in your environment, e.g. `D8="$ANDROID_SDK_ROOT/build-tools/29.0.2/d8"` +# 2. Make sure that you have built the library artifacts using ./gradlew assemble from the realm folder. +# 3. Run the script: `> sh ./print_library_size.sh` +# +# Note: This script has only been tested on MacOS + +HERE=`pwd` + +cd "$(dirname $0)/.." + +cd realm/realm-library/build/outputs/aar + +# Base variant +echo "Analyzing Base..." +rm -rf unzippedBase +unzip -qq realm-android-library-base-release.aar -d unzippedBase +sh "$D8" --release --output ./unzippedBase unzippedBase/classes.jar > /dev/null 2>&1 +cat ./unzippedBase/classes.dex | head -c 92 | tail -c 4 | hexdump -e '1/4 "Method count: %d\n"' +find ./unzippedBase -name '*.so' -exec stat -f"%z %N" {} \; + +# ObjectServer variant +echo "\nAnalyzing ObjectServer..." +rm -rf unzippedObjectServer +unzip -qq realm-android-library-objectServer-release.aar -d unzippedObjectServer +sh "$D8" --release --output ./unzippedObjectServer unzippedObjectServer/classes.jar > /dev/null 2>&1 +cat ./unzippedObjectServer/classes.dex | head -c 92 | tail -c 4 | hexdump -e '1/4 "Method count: %d\n"' +find ./unzippedObjectServer -name '*.so' -exec stat -f"%z %N" {} \; + +cd $HERE \ No newline at end of file From 6f05d27f1d0a40f6cd2967e21d8fe025a6fec701 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Fri, 21 Feb 2020 08:54:10 +0100 Subject: [PATCH 42/47] Also print AAR size --- tools/{print_library_size.sh => analyze_realm_metrics.sh} | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) rename tools/{print_library_size.sh => analyze_realm_metrics.sh} (77%) diff --git a/tools/print_library_size.sh b/tools/analyze_realm_metrics.sh similarity index 77% rename from tools/print_library_size.sh rename to tools/analyze_realm_metrics.sh index fee8830cb3..6b29c55f78 100755 --- a/tools/print_library_size.sh +++ b/tools/analyze_realm_metrics.sh @@ -1,10 +1,10 @@ #!/bin/sh -# This script will print the size of the Realm libraries. +# This script will print metrics for the Realm library being deployed to end users. # To run it: # 1. Make sure that $D8 is defined in your environment, e.g. `D8="$ANDROID_SDK_ROOT/build-tools/29.0.2/d8"` -# 2. Make sure that you have built the library artifacts using ./gradlew assemble from the realm folder. -# 3. Run the script: `> sh ./print_library_size.sh` +# 2. Make sure that you have built the library artifacts using `./gradlew assembleRelease` from the realm folder. +# 3. Run the script: `> sh ./analyze_realm_metrics.sh` # # Note: This script has only been tested on MacOS @@ -16,6 +16,7 @@ cd realm/realm-library/build/outputs/aar # Base variant echo "Analyzing Base..." +stat -f"AAR size: %z" realm-android-library-base-release.aar rm -rf unzippedBase unzip -qq realm-android-library-base-release.aar -d unzippedBase sh "$D8" --release --output ./unzippedBase unzippedBase/classes.jar > /dev/null 2>&1 @@ -24,6 +25,7 @@ find ./unzippedBase -name '*.so' -exec stat -f"%z %N" {} \; # ObjectServer variant echo "\nAnalyzing ObjectServer..." +stat -f"AAR size: %z" realm-android-library-objectServer-release.aar rm -rf unzippedObjectServer unzip -qq realm-android-library-objectServer-release.aar -d unzippedObjectServer sh "$D8" --release --output ./unzippedObjectServer unzippedObjectServer/classes.jar > /dev/null 2>&1 From 36da844e9d9692ee2b70df43f35c6f189567fbc1 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Fri, 21 Feb 2020 12:21:33 +0100 Subject: [PATCH 43/47] Add debug for failing tests --- .../src/androidTest/java/io/realm/RealmAsyncQueryTests.java | 2 ++ .../realm-library/src/androidTest/java/io/realm/RealmTests.java | 1 + 2 files changed, 3 insertions(+) diff --git a/realm/realm-library/src/androidTest/java/io/realm/RealmAsyncQueryTests.java b/realm/realm-library/src/androidTest/java/io/realm/RealmAsyncQueryTests.java index b0a58f1085..80b97fa0ae 100644 --- a/realm/realm-library/src/androidTest/java/io/realm/RealmAsyncQueryTests.java +++ b/realm/realm-library/src/androidTest/java/io/realm/RealmAsyncQueryTests.java @@ -1347,12 +1347,14 @@ public void onChange(RealmResults element) { if (updatesTriggered.get()) { // Step 4: Test finished after all results's onChange gets called the 2nd time. int count = secondOnChangeCounter.addAndGet(1); + RealmLog.error("SecondOnChangeCounter: " + count); if (count == TEST_COUNT) { realm.removeAllChangeListeners(); looperThread.testComplete(); } } else { int count = firstOnChangeCounter.addAndGet(1); + RealmLog.error("firstOnChangeCounter: " + count); if (count == TEST_COUNT) { // Step 3: Commits the transaction to trigger queries updates. updatesTriggered.set(true); diff --git a/realm/realm-library/src/androidTest/java/io/realm/RealmTests.java b/realm/realm-library/src/androidTest/java/io/realm/RealmTests.java index 2028a668aa..30db160ca7 100644 --- a/realm/realm-library/src/androidTest/java/io/realm/RealmTests.java +++ b/realm/realm-library/src/androidTest/java/io/realm/RealmTests.java @@ -4600,6 +4600,7 @@ public void run() { results.addChangeListener(new OrderedRealmCollectionChangeListener>() { @Override public void onChange(RealmResults results, OrderedCollectionChangeSet changeSet) { + RealmLog.error("Size: " + results.size()); for (AllJavaTypes obj : results) { String s = obj.getFieldString(); } From a9a1402a963727fcd95bf94fa4bc365e8f324b92 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Fri, 21 Feb 2020 14:21:03 +0100 Subject: [PATCH 44/47] Has notifications gotten slower? --- realm/realm-library/build.gradle | 6 +++--- .../src/testUtils/java/io/realm/TestHelper.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/realm/realm-library/build.gradle b/realm/realm-library/build.gradle index bc289641a1..215e772f85 100644 --- a/realm/realm-library/build.gradle +++ b/realm/realm-library/build.gradle @@ -559,7 +559,7 @@ task deployCore(group: 'build setup', description: 'Deploy the latest version of } } -publishToMavenLocal.dependsOn assemble +publishToMavenLocal.dependsOn assembleRelease preBuild.dependsOn deployCore if (project.hasProperty('dontCleanJniFiles')) { @@ -635,7 +635,7 @@ android.productFlavors.all { flavor -> // BINTRAY task("bintrayAar${flavor.name.capitalize()}", type: Exec) { - dependsOn "assemble${flavor.name.capitalize()}" + dependsOn "assemble${flavor.name.capitalize()}Release" group = 'Publishing' commandLine 'curl', '-X', @@ -689,7 +689,7 @@ android.productFlavors.all { flavor -> // OJO task("ojoAar${flavor.name.capitalize()}", type: Exec) { - dependsOn "assemble${flavor.name.capitalize()}" + dependsOn "assemble${flavor.name.capitalize()}Release" group = 'Publishing' commandLine 'curl', '-X', diff --git a/realm/realm-library/src/testUtils/java/io/realm/TestHelper.java b/realm/realm-library/src/testUtils/java/io/realm/TestHelper.java index 8bb97d2e84..2c3fdeedd9 100644 --- a/realm/realm-library/src/testUtils/java/io/realm/TestHelper.java +++ b/realm/realm-library/src/testUtils/java/io/realm/TestHelper.java @@ -73,7 +73,7 @@ public class TestHelper { public static final int VERY_SHORT_WAIT_SECS = 1; public static final int SHORT_WAIT_SECS = 10; - public static final int STANDARD_WAIT_SECS = 100; + public static final int STANDARD_WAIT_SECS = 200; private static final Charset UTF_8 = Charset.forName("UTF-8"); private static final Random RANDOM = new Random(); From 67be8ea7c2638a8eb54905c0b056f1ae28cabf18 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Fri, 21 Feb 2020 15:02:49 +0100 Subject: [PATCH 45/47] Merge mistake --- realm/realm-library/build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/realm/realm-library/build.gradle b/realm/realm-library/build.gradle index 215e772f85..bc289641a1 100644 --- a/realm/realm-library/build.gradle +++ b/realm/realm-library/build.gradle @@ -559,7 +559,7 @@ task deployCore(group: 'build setup', description: 'Deploy the latest version of } } -publishToMavenLocal.dependsOn assembleRelease +publishToMavenLocal.dependsOn assemble preBuild.dependsOn deployCore if (project.hasProperty('dontCleanJniFiles')) { @@ -635,7 +635,7 @@ android.productFlavors.all { flavor -> // BINTRAY task("bintrayAar${flavor.name.capitalize()}", type: Exec) { - dependsOn "assemble${flavor.name.capitalize()}Release" + dependsOn "assemble${flavor.name.capitalize()}" group = 'Publishing' commandLine 'curl', '-X', @@ -689,7 +689,7 @@ android.productFlavors.all { flavor -> // OJO task("ojoAar${flavor.name.capitalize()}", type: Exec) { - dependsOn "assemble${flavor.name.capitalize()}Release" + dependsOn "assemble${flavor.name.capitalize()}" group = 'Publishing' commandLine 'curl', '-X', From 6c73e8a71dc864f6a1f6a9cb42917ee5ad0b77b2 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Fri, 21 Feb 2020 15:47:42 +0100 Subject: [PATCH 46/47] Cleanup --- CHANGELOG.md | 2 +- README.md | 8 ++++---- .../androidTest/java/io/realm/RealmAsyncQueryTests.java | 2 -- .../src/androidTest/java/io/realm/RealmTests.java | 1 - realm/realm-library/src/main/cpp/CMakeLists.txt | 2 +- tools/analyze_realm_metrics.sh | 2 +- 6 files changed, 7 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31fc5bb96b..38ad95ce45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,7 +32,7 @@ NOTE: This version bumps the Realm file format to version 10. It is not possible ### Internal * `OsSharedRealm.VersionID.hashCode()` was not implemented correctly and included the memory location in the hashcode. * OKHttp was upgraded to 3.10.0 from 3.9.0. -* The NDK has been upgraded from NDK r10e to r21. +* The NDK has been upgraded from r10e to r21. * The compiler used for C++ code has changed from GCC to Clang. * OpenSSL used by Realms encryption layer has been upgraded from 1.0.2k to 1.1.1b. diff --git a/README.md b/README.md index 57cb6763a9..055be13bf0 100644 --- a/README.md +++ b/README.md @@ -76,15 +76,15 @@ You may unzip the file wherever you choose. For macOS, a suggested location is * If you will be building with Android Studio, you will need to tell it to use the correct NDK. If you installed it using the SDK Manager, it will automatically be detected. Otherwise, you need to define the variable `ndk.dir` in `realm/local.properties` and assign it the full pathname of the directory that you unzipped above. Note that there is a `local.properites` in the root directory that is *not* the one that needs to be edited. ``` - ndk.dir=/Users//Library/android-ndk-r21/ + ndk.dir=/Users//Library/android-sdk/ndk/21.0.6113669 ``` - * Add two environment variables to your profile (presuming you installed the NDK in `~/Library/android-ndk-r21`): + * Add two environment variables to your profile (presuming you installed the NDK using the SDK Manager): ``` - export ANDROID_HOME=~/Library/Android/sdk - export ANDROID_NDK_HOME=~/Library/android-ndk-r21 + export ANDROID_HOME=~/Library/android-sdk + export ANDROID_NDK_HOME=~/Library/android-sdk/ndk/21.0.6113669 ``` * If you are launching Android Studio from the macOS Finder, you should also run the following two commands: diff --git a/realm/realm-library/src/androidTest/java/io/realm/RealmAsyncQueryTests.java b/realm/realm-library/src/androidTest/java/io/realm/RealmAsyncQueryTests.java index 80b97fa0ae..b0a58f1085 100644 --- a/realm/realm-library/src/androidTest/java/io/realm/RealmAsyncQueryTests.java +++ b/realm/realm-library/src/androidTest/java/io/realm/RealmAsyncQueryTests.java @@ -1347,14 +1347,12 @@ public void onChange(RealmResults element) { if (updatesTriggered.get()) { // Step 4: Test finished after all results's onChange gets called the 2nd time. int count = secondOnChangeCounter.addAndGet(1); - RealmLog.error("SecondOnChangeCounter: " + count); if (count == TEST_COUNT) { realm.removeAllChangeListeners(); looperThread.testComplete(); } } else { int count = firstOnChangeCounter.addAndGet(1); - RealmLog.error("firstOnChangeCounter: " + count); if (count == TEST_COUNT) { // Step 3: Commits the transaction to trigger queries updates. updatesTriggered.set(true); diff --git a/realm/realm-library/src/androidTest/java/io/realm/RealmTests.java b/realm/realm-library/src/androidTest/java/io/realm/RealmTests.java index 30db160ca7..2028a668aa 100644 --- a/realm/realm-library/src/androidTest/java/io/realm/RealmTests.java +++ b/realm/realm-library/src/androidTest/java/io/realm/RealmTests.java @@ -4600,7 +4600,6 @@ public void run() { results.addChangeListener(new OrderedRealmCollectionChangeListener>() { @Override public void onChange(RealmResults results, OrderedCollectionChangeSet changeSet) { - RealmLog.error("Size: " + results.size()); for (AllJavaTypes obj : results) { String s = obj.getFieldString(); } diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index 9deb509f21..81dab37a48 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -142,7 +142,7 @@ endif() set(WARNING_CXX_FLAGS "-Werror -Wall -Wextra -pedantic -Wmissing-declarations \ -Wempty-body -Wparentheses -Wunknown-pragmas -Wunreachable-code \ -Wno-missing-field-initializers -Wno-unevaluated-expression -Wno-unreachable-code") -set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -fdata-sections -pthread -frtti -fvisibility=hidden -fvisibility-inlines-hidden -fsigned-char -std=c++14") +set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ANDROID -DREALM_HAVE_CONFIG -DPIC -fdata-sections -pthread -frtti -fvisibility=hidden -fsigned-char -fno-stack-protector -std=c++14") if (build_SYNC) set(REALM_COMMON_CXX_FLAGS "${REALM_COMMON_CXX_FLAGS} -DREALM_ENABLE_SYNC=1") endif() diff --git a/tools/analyze_realm_metrics.sh b/tools/analyze_realm_metrics.sh index 6b29c55f78..8f09a22ba0 100755 --- a/tools/analyze_realm_metrics.sh +++ b/tools/analyze_realm_metrics.sh @@ -32,4 +32,4 @@ sh "$D8" --release --output ./unzippedObjectServer unzippedObjectServer/classes. cat ./unzippedObjectServer/classes.dex | head -c 92 | tail -c 4 | hexdump -e '1/4 "Method count: %d\n"' find ./unzippedObjectServer -name '*.so' -exec stat -f"%z %N" {} \; -cd $HERE \ No newline at end of file +cd $HERE From cacac37d5f5bfb1167d37c8278209c0b32953b08 Mon Sep 17 00:00:00 2001 From: Christian Melchior Date: Mon, 24 Feb 2020 21:32:22 +0100 Subject: [PATCH 47/47] PR feedback --- realm/realm-library/src/main/cpp/CMakeLists.txt | 2 +- .../main/java/io/realm/internal/sync/PermissionHelper.java | 5 +++-- .../java/io/realm/objectserver/ProgressListenerTests.java | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/realm/realm-library/src/main/cpp/CMakeLists.txt b/realm/realm-library/src/main/cpp/CMakeLists.txt index 81dab37a48..677d592023 100644 --- a/realm/realm-library/src/main/cpp/CMakeLists.txt +++ b/realm/realm-library/src/main/cpp/CMakeLists.txt @@ -148,7 +148,7 @@ if (build_SYNC) endif() set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -Oz") # -ggdb doesn't play well with -flto -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -ggdb -Og") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -glldb -g") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${REALM_COMMON_CXX_FLAGS} ${WARNING_CXX_FLAGS} ${ABI_CXX_FLAGS}") # Set Linker flags flags diff --git a/realm/realm-library/src/main/java/io/realm/internal/sync/PermissionHelper.java b/realm/realm-library/src/main/java/io/realm/internal/sync/PermissionHelper.java index d19f7b6ff7..c2041e248c 100644 --- a/realm/realm-library/src/main/java/io/realm/internal/sync/PermissionHelper.java +++ b/realm/realm-library/src/main/java/io/realm/internal/sync/PermissionHelper.java @@ -18,6 +18,7 @@ import io.realm.Realm; import io.realm.RealmList; import io.realm.RealmObject; +import io.realm.internal.Util; import io.realm.internal.annotations.ObjectServer; import io.realm.sync.permissions.Permission; import io.realm.sync.permissions.Role; @@ -38,8 +39,8 @@ public class PermissionHelper { * @return */ public static Permission findOrCreatePermissionForRole(RealmObject container, RealmList permissions, String roleName) { - if (roleName == null) { - throw new IllegalArgumentException("Non-null 'roleName' required."); + if (Util.isEmptyString(roleName)) { + throw new IllegalArgumentException("Non-empty 'roleName' required."); } if (!container.isManaged()) { throw new IllegalStateException("'findOrCreate()' can only be called on managed objects."); diff --git a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java index 45bb770a4b..82da398c07 100644 --- a/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java +++ b/realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/ProgressListenerTests.java @@ -52,7 +52,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -@Ignore("FIXME: Most of these are currently broken. See https://mongodb.slack.com/archives/CL7EWAHCY/p1582101560005200") +@Ignore("FIXME: Most of these are currently broken. See https://jira.mongodb.org/browse/RSYNC-101") @RunWith(AndroidJUnit4.class) public class ProgressListenerTests extends StandardIntegrationTest {