1+ /**
2+ * Modified MIT License
3+ *
4+ * Copyright 2016 OneSignal
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * 1. The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * 2. All copies of substantial portions of the Software may only be used in connection
17+ * with services provided by OneSignal.
18+ *
19+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+ * THE SOFTWARE.
26+ */
27+
28+ #if UNITY_ANDROID && UNITY_EDITOR
29+ using UnityEditor ;
30+ using System . IO ;
31+ using UnityEngine ;
32+
33+ using Google . JarResolver ;
34+
35+ [ InitializeOnLoad ]
36+ public class OneSignalEditorScript {
37+
38+ private static readonly string PluginName = "OneSignal" ;
39+ private static readonly string PLAY_SERVICES_VERSION = "9+" ;
40+ public static PlayServicesSupport svcSupport ;
41+
42+ static OneSignalEditorScript ( ) {
43+ createOneSignalAndroidManifest ( ) ;
44+ addGMSLibrary ( ) ;
45+ }
46+
47+ private static void addGMSLibrary ( ) {
48+ svcSupport = PlayServicesSupport . CreateInstance ( PluginName ,
49+ EditorPrefs . GetString ( "AndroidSdkRoot" ) ,
50+ "ProjectSettings" ) ;
51+
52+ svcSupport . DependOn ( "com.google.android.gms" , "play-services-gcm" , PLAY_SERVICES_VERSION ) ;
53+ svcSupport . DependOn ( "com.google.android.gms" , "play-services-location" , PLAY_SERVICES_VERSION ) ;
54+ // Adds play-services-base, play-services-basement, play-services-iid, and support-v4 will be automaticly added.
55+ // Also adds play-services-tasks but this isn't used by OneSignal, it just added as a depency from the above.
56+
57+
58+ // Setting 8.3+ does not work with unity-jar-resolver-1.2.0 and GooglePlayGamesPlugin-0.9.34.
59+ // It creates conflicting aar files with mismatched version of 8.4 and 9.4
60+ // svcSupport.DependOn("com.google.android.gms", "play-services-gcm", "8.3+");
61+ // svcSupport.DependOn("com.google.android.gms", "play-services-location", "8.3+");
62+ // play-services-base, play-services-basement, and support-v4 will be automaticly added.
63+ // play-services-maps and play-services-measurement are not used by OneSignal
64+ // but are included as depencies from the other parts of play-services.
65+ }
66+
67+ // Copies `AndroidManifestTemplate.xml` to `AndroidManifest.xml`
68+ // then replace `${manifestApplicationId}` with current packagename in the Unity settings.
69+ private static void createOneSignalAndroidManifest ( ) {
70+ string oneSignalConfigPath = "Assets/Plugins/Android/OneSignalConfig/" ;
71+ string manifestFullPath = oneSignalConfigPath + "AndroidManifest.xml" ;
72+
73+ File . Copy ( oneSignalConfigPath + "AndroidManifestTemplate.xml" , manifestFullPath , true ) ;
74+
75+ StreamReader streamReader = new StreamReader ( manifestFullPath ) ;
76+ string body = streamReader . ReadToEnd ( ) ;
77+ streamReader . Close ( ) ;
78+
79+ body = body . Replace ( "${manifestApplicationId}" , PlayerSettings . bundleIdentifier ) ;
80+ using ( var streamWriter = new StreamWriter ( manifestFullPath , false ) )
81+ {
82+ streamWriter . Write ( body ) ;
83+ }
84+ }
85+ }
86+ #endif
0 commit comments