From 09b4ca39e216935f16b356ac7745b586148b5f89 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Thu, 9 Jun 2016 17:03:31 -0400 Subject: [PATCH] [Mono.Data.Sqlite] Import from monodroid/6a8eb978. (#70) Import `Mono.Data.Sqlite.dll` from monodroid/6a8eb978. `Mono.Data.Sqlite.dll` needs to embed a version of SQLite because Android N will only support allow using native libraries which are [part of the Android NDK or are distributed with the application][0]. Consequently, the only way that `Mono.Data.Sqlite.dll` can be used is if SQLite is "somehow" included within all apps which use `Mono.Data.Sqlite.dll`, and the easiest way to do that is to compile SQLite, naming the library `libsqlite3_xamarin.so` (for uniqueness), and making use of the [`@(EmbeddedNativeLibrary)` build action][1]. [0]: https://web.archive.org/web/20160401151536/http://developer.android.com/preview/behavior-changes.html?utm_campaign=android_launch_n_030916&utm_source=anddev&utm_medium=blog#ndk [1]: https://developer.xamarin.com/guides/android/under_the_hood/build_process/#AndroidNativeLibrary --- .gitmodules | 3 + Configuration.props | 6 + Xamarin.Android.sln | 30 ++++ external/sqlite | 1 + src/Mono.Data.Sqlite/Mono.Data.Sqlite.csproj | 168 ++++++++++++++++++ .../Mono.Data.Sqlite.dll.config | 3 + src/sqlite-xamarin/.gitignore | 7 + src/sqlite-xamarin/sqlite-xamarin.mdproj | 30 ++++ src/sqlite-xamarin/sqlite-xamarin.targets | 41 +++++ src/sqlite-xamarin/src-jni/Android.mk | 61 +++++++ src/sqlite-xamarin/src-jni/Application.mk | 1 + 11 files changed, 351 insertions(+) create mode 160000 external/sqlite create mode 100644 src/Mono.Data.Sqlite/Mono.Data.Sqlite.csproj create mode 100644 src/Mono.Data.Sqlite/Mono.Data.Sqlite.dll.config create mode 100644 src/sqlite-xamarin/.gitignore create mode 100644 src/sqlite-xamarin/sqlite-xamarin.mdproj create mode 100644 src/sqlite-xamarin/sqlite-xamarin.targets create mode 100644 src/sqlite-xamarin/src-jni/Android.mk create mode 100644 src/sqlite-xamarin/src-jni/Application.mk diff --git a/.gitmodules b/.gitmodules index f5753d5c5d5..bdd72086a02 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ path = external/mxe url = https://github.com/xamarin/mxe.git branch = xamarin +[submodule "external/sqlite"] + path = external/sqlite + url = https://github.com/xamarin/sqlite.git diff --git a/Configuration.props b/Configuration.props index d2be68bcaec..c41d2a15e4c 100644 --- a/Configuration.props +++ b/Configuration.props @@ -21,10 +21,16 @@ $(AndroidToolchainDirectory)\ndk host-$(HostOS):armeabi-v7a $(MSBuildThisFileDirectory)external\mono + $(MSBuildThisFileDirectory)external\sqlite $(MSBuildThisFileDirectory) + armeabi;armeabi-v7a;x86 + arm64-v8a;x86_64 + $(AllSupported32BitTargetAndroidAbis);$(AllSupported64BitTargetAndroidAbis) $([System.IO.Path]::GetFullPath ('$(AndroidMxeInstallPrefix)')) + $([System.IO.Path]::GetFullPath ('$(MonoSourceDirectory)')) + $([System.IO.Path]::GetFullPath ('$(SqliteSourceDirectory)')) diff --git a/Xamarin.Android.sln b/Xamarin.Android.sln index fa072b84d19..de4d20d7a6f 100644 --- a/Xamarin.Android.sln +++ b/Xamarin.Android.sln @@ -73,6 +73,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "class-parse", "external\Jav EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "logcat-parse", "external\Java.Interop\tools\logcat-parse\logcat-parse.csproj", "{7387E151-48E3-4885-B2CA-A74434A34045}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Data.Sqlite", "src\Mono.Data.Sqlite\Mono.Data.Sqlite.csproj", "{26781D3A-FF20-4F55-9824-C8A06AA9E484}" +EndProject +Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "sqlite-xamarin", "src\sqlite-xamarin\sqlite-xamarin.mdproj", "{B8F799C5-D7CE-4E09-9CE6-BAA4173E7EC8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|AnyCPU = Debug|AnyCPU @@ -322,6 +326,30 @@ Global {7387E151-48E3-4885-B2CA-A74434A34045}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU {7387E151-48E3-4885-B2CA-A74434A34045}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU {7387E151-48E3-4885-B2CA-A74434A34045}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU + {26781D3A-FF20-4F55-9824-C8A06AA9E484}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU + {26781D3A-FF20-4F55-9824-C8A06AA9E484}.Debug|AnyCPU.Build.0 = Debug|Any CPU + {26781D3A-FF20-4F55-9824-C8A06AA9E484}.Release|AnyCPU.ActiveCfg = Release|Any CPU + {26781D3A-FF20-4F55-9824-C8A06AA9E484}.Release|AnyCPU.Build.0 = Release|Any CPU + {26781D3A-FF20-4F55-9824-C8A06AA9E484}.XAIntegrationDebug|Any CPU.ActiveCfg = Debug|Any CPU + {26781D3A-FF20-4F55-9824-C8A06AA9E484}.XAIntegrationDebug|Any CPU.Build.0 = Debug|Any CPU + {26781D3A-FF20-4F55-9824-C8A06AA9E484}.XAIntegrationRelease|Any CPU.ActiveCfg = Debug|Any CPU + {26781D3A-FF20-4F55-9824-C8A06AA9E484}.XAIntegrationRelease|Any CPU.Build.0 = Debug|Any CPU + {26781D3A-FF20-4F55-9824-C8A06AA9E484}.XAIntegrationDebug|AnyCPU.ActiveCfg = Debug|Any CPU + {26781D3A-FF20-4F55-9824-C8A06AA9E484}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU + {26781D3A-FF20-4F55-9824-C8A06AA9E484}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU + {26781D3A-FF20-4F55-9824-C8A06AA9E484}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU + {B8F799C5-D7CE-4E09-9CE6-BAA4173E7EC8}.Debug|AnyCPU.ActiveCfg = Debug|Any CPU + {B8F799C5-D7CE-4E09-9CE6-BAA4173E7EC8}.Debug|AnyCPU.Build.0 = Debug|Any CPU + {B8F799C5-D7CE-4E09-9CE6-BAA4173E7EC8}.Release|AnyCPU.ActiveCfg = Release|Any CPU + {B8F799C5-D7CE-4E09-9CE6-BAA4173E7EC8}.Release|AnyCPU.Build.0 = Release|Any CPU + {B8F799C5-D7CE-4E09-9CE6-BAA4173E7EC8}.XAIntegrationDebug|Any CPU.ActiveCfg = Debug|Any CPU + {B8F799C5-D7CE-4E09-9CE6-BAA4173E7EC8}.XAIntegrationDebug|Any CPU.Build.0 = Debug|Any CPU + {B8F799C5-D7CE-4E09-9CE6-BAA4173E7EC8}.XAIntegrationRelease|Any CPU.ActiveCfg = Debug|Any CPU + {B8F799C5-D7CE-4E09-9CE6-BAA4173E7EC8}.XAIntegrationRelease|Any CPU.Build.0 = Debug|Any CPU + {B8F799C5-D7CE-4E09-9CE6-BAA4173E7EC8}.XAIntegrationDebug|AnyCPU.ActiveCfg = Debug|Any CPU + {B8F799C5-D7CE-4E09-9CE6-BAA4173E7EC8}.XAIntegrationDebug|AnyCPU.Build.0 = Debug|Any CPU + {B8F799C5-D7CE-4E09-9CE6-BAA4173E7EC8}.XAIntegrationRelease|AnyCPU.ActiveCfg = Debug|Any CPU + {B8F799C5-D7CE-4E09-9CE6-BAA4173E7EC8}.XAIntegrationRelease|AnyCPU.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {8FF78EB6-6FC8-46A7-8A15-EBBA9045C5FA} = {E351F97D-EA4F-4E7F-AAA0-8EBB1F2A4A62} @@ -356,6 +384,8 @@ Global {1A4B041A-842F-40B3-A50D-49E01D30BD18} = {04E3E11E-B47D-4599-8AFC-50515A95E715} {38C762AB-8FD1-44DE-9855-26AAE7129DC3} = {864062D3-A415-4A6F-9324-5820237BA058} {7387E151-48E3-4885-B2CA-A74434A34045} = {864062D3-A415-4A6F-9324-5820237BA058} + {26781D3A-FF20-4F55-9824-C8A06AA9E484} = {04E3E11E-B47D-4599-8AFC-50515A95E715} + {B8F799C5-D7CE-4E09-9CE6-BAA4173E7EC8} = {04E3E11E-B47D-4599-8AFC-50515A95E715} EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution Policies = $0 diff --git a/external/sqlite b/external/sqlite new file mode 160000 index 00000000000..382b7beebed --- /dev/null +++ b/external/sqlite @@ -0,0 +1 @@ +Subproject commit 382b7beebed97d38f55c7703b1af879c5c323d7c diff --git a/src/Mono.Data.Sqlite/Mono.Data.Sqlite.csproj b/src/Mono.Data.Sqlite/Mono.Data.Sqlite.csproj new file mode 100644 index 00000000000..ef28ae621cd --- /dev/null +++ b/src/Mono.Data.Sqlite/Mono.Data.Sqlite.csproj @@ -0,0 +1,168 @@ + + + + Debug + AnyCPU + {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + {26781D3A-FF20-4F55-9824-C8A06AA9E484} + Library + Mono.Data.Sqlite + Assets + Resources + Resource + Resources\Resource.designer.cs + True + Mono.Data.Sqlite + True + False + + + + $(AndroidFrameworkVersion) + $(MonoSourceFullPath)\mcs\class\mono.pub + + + true + full + false + ..\..\bin\$(Configuration)\lib\xbuild-frameworks\MonoAndroid\v1.0 + DEBUG;TRACE;NET_4_0;NET_4_5;MONO;DISABLE_CAS_USE;SQLITE_STANDARD;MONODROID + prompt + 4 + None + false + true + + + true + ..\..\bin\$(Configuration)\lib\xbuild-frameworks\MonoAndroid\v1.0 + prompt + 4 + false + true + NET_4_0;NET_4_5;MONO;DISABLE_CAS_USE;SQLITE_STANDARD;MONODROID + + + + + + + + + + + + PreserveNewest + + + + + Android.Runtime\CPUArchitecture.cs + + + Assembly\AssemblyInfo.cs + + + Mono.Data.Sqlite_2.0\MonoPInvokeCallbackAttribute.cs + + + Mono.Data.Sqlite_2.0\SQLite3.cs + + + Mono.Data.Sqlite_2.0\SQLite3_UTF16.cs + + + Mono.Data.Sqlite_2.0\SQLiteBase.cs + + + Mono.Data.Sqlite_2.0\SQLiteCommandBuilder.cs + + + Mono.Data.Sqlite_2.0\SQLiteCommand.cs + + + Mono.Data.Sqlite_2.0\SQLiteConnection.cs + + + Mono.Data.Sqlite_2.0\LINQ\SQLiteConnection_Linq.cs + + + Mono.Data.Sqlite_2.0\SQLiteConnectionPool.cs + + + Mono.Data.Sqlite_2.0\SQLiteConnectionStringBuilder.cs + + + Mono.Data.Sqlite_2.0\SQLiteConvert.cs + + + Mono.Data.Sqlite_2.0\SQLiteDataAdapter.cs + + + Mono.Data.Sqlite_2.0\SQLiteDataReader.cs + + + Mono.Data.Sqlite_2.0\SqliteDataSourceEnumerator.cs + + + Mono.Data.Sqlite_2.0\SQLiteEnlistment.cs + + + Mono.Data.Sqlite_2.0\SQLiteException.cs + + + Mono.Data.Sqlite_2.0\SQLiteFactory.cs + + + Mono.Data.Sqlite_2.0\LINQ\SQLiteFactory_Linq.cs + + + Mono.Data.Sqlite_2.0\SQLiteFunctionAttribute.cs + + + Mono.Data.Sqlite_2.0\SQLiteFunction.cs + + + Mono.Data.Sqlite_2.0\SQLiteKeyReader.cs + + + Mono.Data.Sqlite_2.0\SQLiteMetaDataCollectionNames.cs + + + Mono.Data.Sqlite_2.0\SQLiteParameterCollection.cs + + + Mono.Data.Sqlite_2.0\SQLiteParameter.cs + + + Mono.Data.Sqlite_2.0\SQLiteStatement.cs + + + Mono.Data.Sqlite_2.0\SQLiteTransaction.cs + + + Mono.Data.Sqlite_2.0\SR.Designer.cs + + + Mono.Data.Sqlite_2.0\UnsafeNativeMethods.cs + + + Locale.cs + + + Consts.cs + + + + + <_SupportedAbi Include="$(AllSupportedTargetAndroidAbis)" /> + + + + + {B8F799C5-D7CE-4E09-9CE6-BAA4173E7EC8} + sqlite-xamarin + False + + + diff --git a/src/Mono.Data.Sqlite/Mono.Data.Sqlite.dll.config b/src/Mono.Data.Sqlite/Mono.Data.Sqlite.dll.config new file mode 100644 index 00000000000..5e01176193d --- /dev/null +++ b/src/Mono.Data.Sqlite/Mono.Data.Sqlite.dll.config @@ -0,0 +1,3 @@ + + + diff --git a/src/sqlite-xamarin/.gitignore b/src/sqlite-xamarin/.gitignore new file mode 100644 index 00000000000..79939837e36 --- /dev/null +++ b/src/sqlite-xamarin/.gitignore @@ -0,0 +1,7 @@ +.stamp +build.gradle +gradle/ +gradlew +gradlew.bat +src/ + diff --git a/src/sqlite-xamarin/sqlite-xamarin.mdproj b/src/sqlite-xamarin/sqlite-xamarin.mdproj new file mode 100644 index 00000000000..b8a560c8e78 --- /dev/null +++ b/src/sqlite-xamarin/sqlite-xamarin.mdproj @@ -0,0 +1,30 @@ + + + Debug + AnyCPU + GenericProject + {B8F799C5-D7CE-4E09-9CE6-BAA4173E7EC8} + + + + ..\..\bin\Debug\ + + + ..\..\bin\Release\ + + + + + _CreateProject; + _NdkBuild; + + + + + + {8FF78EB6-6FC8-46A7-8A15-EBBA9045C5FA} + android-toolchain + False + + + diff --git a/src/sqlite-xamarin/sqlite-xamarin.targets b/src/sqlite-xamarin/sqlite-xamarin.targets new file mode 100644 index 00000000000..d05ff039d9b --- /dev/null +++ b/src/sqlite-xamarin/sqlite-xamarin.targets @@ -0,0 +1,41 @@ + + + + + + + + + + + <_SupportedAbi Include="$(AllSupportedTargetAndroidAbis)" /> + + <_LibSqliteXamarin Include="@(_SupportedAbi->'src\main\libs\%(Identity)\libsqlite3_xamarin.so')" /> + + + + + + + + + diff --git a/src/sqlite-xamarin/src-jni/Android.mk b/src/sqlite-xamarin/src-jni/Android.mk new file mode 100644 index 00000000000..4b1d63c1c13 --- /dev/null +++ b/src/sqlite-xamarin/src-jni/Android.mk @@ -0,0 +1,61 @@ +# It is based on sqlite/dist/Android.mk with some changes. + +## +## +## Build the library +## +## + +LOCAL_PATH:= $(call my-dir) + +# NOTE the following flags, +# SQLITE_TEMP_STORE=3 causes all TEMP files to go into RAM. and thats the behavior we want +# SQLITE_ENABLE_FTS3 enables usage of FTS3 - NOT FTS1 or 2. +# SQLITE_DEFAULT_AUTOVACUUM=1 causes the databases to be subject to auto-vacuum +minimal_sqlite_flags := \ + -DNO_ANDROID_FUNCS=1 \ + -DHAVE_POSIX_FALLOCATE=0 \ + -DNDEBUG=1 \ + -DHAVE_USLEEP=1 \ + -DSQLITE_HAVE_ISNAN \ + -DSQLITE_DEFAULT_JOURNAL_SIZE_LIMIT=1048576 \ + -DSQLITE_THREADSAFE=2 \ + -DSQLITE_TEMP_STORE=3 \ + -DSQLITE_POWERSAFE_OVERWRITE=1 \ + -DSQLITE_DEFAULT_FILE_FORMAT=4 \ + -DSQLITE_DEFAULT_AUTOVACUUM=1 \ + -DSQLITE_ENABLE_MEMORY_MANAGEMENT=1 \ + -DSQLITE_ENABLE_FTS3 \ + -DSQLITE_ENABLE_FTS3_BACKWARDS \ + -DSQLITE_ENABLE_FTS4 \ + -DSQLITE_OMIT_BUILTIN_TEST \ + -DSQLITE_OMIT_COMPILEOPTION_DIAGS \ + -DSQLITE_OMIT_LOAD_EXTENSION \ + -DSQLITE_DEFAULT_FILE_PERMISSIONS=0600 + +device_sqlite_flags := $(minimal_sqlite_flags) \ + -DHAVE_MALLOC_H=1 + +common_src_files := $(SQLITE_SOURCE_DIR)/dist/sqlite3.c + +# the device library +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := $(common_src_files) + +LOCAL_CFLAGS += $(device_sqlite_flags) + +LOCAL_SHARED_LIBRARIES := libdl + +LOCAL_MODULE:= libsqlite3_xamarin + +LOCAL_C_INCLUDES += $(call include-path-for, system-core)/cutils + +LOCAL_SHARED_LIBRARIES += liblog + +# include android specific methods +#LOCAL_WHOLE_STATIC_LIBRARIES := libsqlite3_xamarin + +include $(BUILD_SHARED_LIBRARY) + + diff --git a/src/sqlite-xamarin/src-jni/Application.mk b/src/sqlite-xamarin/src-jni/Application.mk new file mode 100644 index 00000000000..ceeb0b40ef5 --- /dev/null +++ b/src/sqlite-xamarin/src-jni/Application.mk @@ -0,0 +1 @@ +APP_ABI := armeabi armeabi-v7a arm64-v8a x86 x86_64