@@ -135,7 +135,11 @@ private static void RunPostBuildScript(BuildTarget target, bool preBuild, string
135
135
// - AdSupport.framework
136
136
// - iAd.framework
137
137
138
+ #if UNITY_2019_3_OR_NEWER
139
+ string xcodeTarget = xcodeProject . GetUnityFrameworkTargetGuid ( ) ;
140
+ #else
138
141
string xcodeTarget = xcodeProject . TargetGuidByName ( "Unity-iPhone" ) ;
142
+ #endif
139
143
140
144
UnityEngine . Debug . Log ( "[Adjust]: Adding AdSupport.framework to Xcode project." ) ;
141
145
xcodeProject . AddFrameworkToProject ( xcodeTarget , "AdSupport.framework" , true ) ;
@@ -212,25 +216,35 @@ private static void RunPostProcessTasksAndroid()
212
216
XmlDocument manifestFile = new XmlDocument ( ) ;
213
217
manifestFile . Load ( appManifestPath ) ;
214
218
219
+ bool manifestHasChanged = false ;
220
+
215
221
// Add needed permissions if they are missing.
216
- AddPermissions ( manifestFile ) ;
222
+ manifestHasChanged |= AddPermissions ( manifestFile ) ;
217
223
218
224
// Add intent filter to main activity if it is missing.
219
- AddBroadcastReceiver ( manifestFile ) ;
225
+ manifestHasChanged |= AddBroadcastReceiver ( manifestFile ) ;
220
226
221
- // Save the changes.
222
- manifestFile . Save ( appManifestPath ) ;
227
+ if ( manifestHasChanged )
228
+ {
229
+ // Save the changes.
230
+ manifestFile . Save ( appManifestPath ) ;
223
231
224
- // Clean the manifest file.
225
- CleanManifestFile ( appManifestPath ) ;
232
+ // Clean the manifest file.
233
+ CleanManifestFile ( appManifestPath ) ;
226
234
227
- UnityEngine . Debug . Log ( "[Adjust]: App's AndroidManifest.xml file check and potential modification completed." ) ;
228
- UnityEngine . Debug . Log ( "[Adjust]: Please check if any error message was displayed during this process "
229
- + "and make sure to fix all issues in order to properly use the Adjust SDK in your app." ) ;
235
+ UnityEngine . Debug . Log ( "[Adjust]: App's AndroidManifest.xml file check and potential modification completed." ) ;
236
+ UnityEngine . Debug . Log ( "[Adjust]: Please check if any error message was displayed during this process "
237
+ + "and make sure to fix all issues in order to properly use the Adjust SDK in your app." ) ;
238
+ }
239
+ else
240
+ {
241
+ UnityEngine . Debug . Log ( "[Adjust]: App's AndroidManifest.xml file check completed." ) ;
242
+ UnityEngine . Debug . Log ( "[Adjust]: No modifications performed due to app's AndroidManifest.xml file compatibility." ) ;
243
+ }
230
244
}
231
245
}
232
246
233
- private static void AddPermissions ( XmlDocument manifest )
247
+ private static bool AddPermissions ( XmlDocument manifest )
234
248
{
235
249
// The Adjust SDK needs two permissions to be added to you app's manifest file:
236
250
// <uses-permission android:name="android.permission.INTERNET" />
@@ -274,13 +288,16 @@ private static void AddPermissions(XmlDocument manifest)
274
288
}
275
289
}
276
290
291
+ bool manifestHasChanged = false ;
292
+
277
293
// If android.permission.INTERNET permission is missing, add it.
278
294
if ( ! hasInternetPermission )
279
295
{
280
296
XmlElement element = manifest . CreateElement ( "uses-permission" ) ;
281
297
element . SetAttribute ( "android__name" , "android.permission.INTERNET" ) ;
282
298
manifestRoot . AppendChild ( element ) ;
283
299
UnityEngine . Debug . Log ( "[Adjust]: android.permission.INTERNET permission successfully added to your app's AndroidManifest.xml file." ) ;
300
+ manifestHasChanged = true ;
284
301
}
285
302
else
286
303
{
@@ -294,6 +311,7 @@ private static void AddPermissions(XmlDocument manifest)
294
311
element . SetAttribute ( "android__name" , "android.permission.ACCESS_WIFI_STATE" ) ;
295
312
manifestRoot . AppendChild ( element ) ;
296
313
UnityEngine . Debug . Log ( "[Adjust]: android.permission.ACCESS_WIFI_STATE permission successfully added to your app's AndroidManifest.xml file." ) ;
314
+ manifestHasChanged = true ;
297
315
}
298
316
else
299
317
{
@@ -307,6 +325,7 @@ private static void AddPermissions(XmlDocument manifest)
307
325
element . SetAttribute ( "android__name" , "android.permission.ACCESS_NETWORK_STATE" ) ;
308
326
manifestRoot . AppendChild ( element ) ;
309
327
UnityEngine . Debug . Log ( "[Adjust]: android.permission.ACCESS_NETWORK_STATE permission successfully added to your app's AndroidManifest.xml file." ) ;
328
+ manifestHasChanged = true ;
310
329
}
311
330
else
312
331
{
@@ -320,14 +339,17 @@ private static void AddPermissions(XmlDocument manifest)
320
339
element . SetAttribute ( "android__name" , "com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE" ) ;
321
340
manifestRoot . AppendChild ( element ) ;
322
341
UnityEngine . Debug . Log ( "[Adjust]: com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE permission successfully added to your app's AndroidManifest.xml file." ) ;
342
+ manifestHasChanged = true ;
323
343
}
324
344
else
325
345
{
326
346
UnityEngine . Debug . Log ( "[Adjust]: Your app's AndroidManifest.xml file already contains com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE permission." ) ;
327
347
}
348
+
349
+ return manifestHasChanged ;
328
350
}
329
351
330
- private static void AddBroadcastReceiver ( XmlDocument manifest )
352
+ private static bool AddBroadcastReceiver ( XmlDocument manifest )
331
353
{
332
354
// We're looking for existance of broadcast receiver in the AndroidManifest.xml
333
355
// Check out the example below how that usually looks like:
@@ -379,7 +401,7 @@ private static void AddBroadcastReceiver(XmlDocument manifest)
379
401
{
380
402
UnityEngine . Debug . LogError ( "[Adjust]: Your app's AndroidManifest.xml file does not contain \" <application>\" node." ) ;
381
403
UnityEngine . Debug . LogError ( "[Adjust]: Unable to add the Adjust broadcast receiver to AndroidManifest.xml." ) ;
382
- return ;
404
+ return false ;
383
405
}
384
406
385
407
// Okay, there's an application node in the AndroidManifest.xml file.
@@ -411,6 +433,8 @@ private static void AddBroadcastReceiver(XmlDocument manifest)
411
433
{
412
434
UnityEngine . Debug . Log ( "[Adjust]: It seems like you are already using Adjust broadcast receiver. Yay." ) ;
413
435
}
436
+
437
+ return false ;
414
438
}
415
439
else
416
440
{
@@ -429,6 +453,8 @@ private static void AddBroadcastReceiver(XmlDocument manifest)
429
453
applicationNode . AppendChild ( receiverElement ) ;
430
454
431
455
UnityEngine . Debug . Log ( "[Adjust]: Adjust broadcast receiver successfully added to your app's AndroidManifest.xml file." ) ;
456
+
457
+ return true ;
432
458
}
433
459
}
434
460
0 commit comments