예제 #1
0
        private void EnableMultidex(string manifestPath, AndroidManifest androidManifest)
        {
#if UNITY_2019_3_OR_NEWER
            if (CheckContainsMultidex(manifestPath, manifestMutlidexApp))
            {
                androidManifest.RemoveMultiDexApplication();
            }
#else
            if (AppodealSettings.Instance.AndroidMultidex)
            {
                if (PlayerSettings.Android.minSdkVersion < AndroidSdkVersions.AndroidApiLevel21)
                {
                    androidManifest.AddMultiDexApplication();

                    if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
                    {
                        if (!AppodealUnityUtils.isGradleEnabled())
                        {
                            new EnableGradle().fixProblem();
                        }

                        var customGradeScript = GetCustomGradleScriptPath();
                        if (string.IsNullOrEmpty(customGradeScript) || !File.Exists(customGradeScript))
                        {
                            if (File.Exists(getDefaultGradleTemplate()))
                            {
                                new CopyGradleScriptAndEnableMultidex().fixProblem();
                            }
                        }
                        else
                        {
                            var settings = new ImportantGradleSettings(customGradeScript);
                            if (!settings.isMultiDexAddedCompletely())
                            {
                                new EnableMultidexInGradle(customGradeScript).fixProblem();
                            }

                            if (!settings.isJavaVersionIncluded())
                            {
                                new EnableJavaVersion(customGradeScript).fixProblem();
                            }
                        }
                    }
                }
            }
            else
            {
                androidManifest.RemoveMultiDexApplication();
            }
#endif
        }
예제 #2
0
        public void OnPreprocessBuild(BuildTarget target, string path)
#endif

        {
            var manifestPath = Path.Combine(Application.dataPath,
                                            "Plugins/Android/appodeal.androidlib/AndroidManifest.xml");

            var androidManifest = new AndroidManifest(manifestPath);

            AddOptionalPermissions(manifestPath, androidManifest);
            AddAdmobAppId(manifestPath, androidManifest);
            EnableMultidex(manifestPath, androidManifest);

            androidManifest.Save();
        }
예제 #3
0
        private void AddOptionalPermissions(string manifestPath, AndroidManifest androidManifest)
        {
            if (AppodealSettings.Instance.AccessCoarseLocationPermission)
            {
                if (!CheckContainsPermission(manifestPath, AppodealUnityUtils.CoarseLocation))
                {
                    androidManifest.SetPermission(AppodealUnityUtils.CoarseLocation);
                }
            }
            else
            {
                if (CheckContainsPermission(manifestPath, AppodealUnityUtils.CoarseLocation))
                {
                    androidManifest.RemovePermission(AppodealUnityUtils.CoarseLocation);
                }
            }

            if (AppodealSettings.Instance.AccessFineLocationPermission)
            {
                if (!CheckContainsPermission(manifestPath, AppodealUnityUtils.FineLocation))
                {
                    androidManifest.SetPermission(AppodealUnityUtils.FineLocation);
                }
            }
            else
            {
                if (CheckContainsPermission(manifestPath, AppodealUnityUtils.FineLocation))
                {
                    androidManifest.RemovePermission(AppodealUnityUtils.FineLocation);
                }
            }

            if (AppodealSettings.Instance.WriteExternalStoragePermission)
            {
                if (!CheckContainsPermission(manifestPath, AppodealUnityUtils.ExternalStorageWrite))
                {
                    androidManifest.SetPermission(AppodealUnityUtils.ExternalStorageWrite);
                }
            }
            else
            {
                if (CheckContainsPermission(manifestPath, AppodealUnityUtils.ExternalStorageWrite))
                {
                    androidManifest.RemovePermission(AppodealUnityUtils.ExternalStorageWrite);
                }
            }


            if (AppodealSettings.Instance.AccessWifiStatePermission)
            {
                if (!CheckContainsPermission(manifestPath, AppodealUnityUtils.AccessWifiState))
                {
                    androidManifest.SetPermission(AppodealUnityUtils.AccessWifiState);
                }
            }
            else
            {
                if (CheckContainsPermission(manifestPath, AppodealUnityUtils.AccessWifiState))
                {
                    androidManifest.RemovePermission(AppodealUnityUtils.AccessWifiState);
                }
            }

            if (AppodealSettings.Instance.VibratePermission)
            {
                if (!CheckContainsPermission(manifestPath, AppodealUnityUtils.Vibrate))
                {
                    androidManifest.SetPermission(AppodealUnityUtils.Vibrate);
                }
            }
            else
            {
                if (CheckContainsPermission(manifestPath, AppodealUnityUtils.Vibrate))
                {
                    androidManifest.RemovePermission(AppodealUnityUtils.Vibrate);
                }
            }
        }
예제 #4
0
        private void AddAdmobAppId(string path, AndroidManifest androidManifest)
        {
            if (File.Exists(Path.Combine(Application.dataPath, "Plugins/Android/AndroidManifest.xml")) &&
                CheckContainsAppId(Path.Combine(Application.dataPath, "Plugins/Android/AndroidManifest.xml")))
            {
                if (File.Exists(path) && CheckContainsAppId(path))
                {
                    androidManifest.RemoveAdmobAppId();
                    Debug.LogWarning(
                        $"AdmobAppId has already been added to {Path.Combine(Application.dataPath, "Plugins/Android/AndroidManifest.xml")}" +
                        "\nRemoving duplicate from internal Appodeal AndroidManifest.xml file.");
                    return;
                }
                else if (!string.IsNullOrEmpty(AppodealSettings.Instance.AdMobAndroidAppId))
                {
                    Debug.LogWarning(
                        $"AdmobAppId has already been added to {Path.Combine(Application.dataPath, "Plugins/Android/AndroidManifest.xml")}" +
                        "\nThe value you set up via 'Appodeal/Appodeal Settings' tool will be ignored.");
                    return;
                }
                else
                {
                    return;
                }
            }

            if (!File.Exists("Assets/Appodeal/Editor/NetworkConfigs/GoogleAdMobDependencies.xml"))
            {
                if (File.Exists(path) && CheckContainsAppId(path))
                {
                    androidManifest.RemoveAdmobAppId();
                }
                Debug.LogWarning(
                    "Missing Admob config (Assets/Appodeal/Editor/NetworkConfigs/GoogleAdMobDependencies.xml). Admob App Id won't be added.");
                return;
            }

            if (!File.Exists(path))
            {
                Debug.LogError(
                    $"Missing internal AndroidManifest {path}." +
                    "\nAdmob App ID can't be added. The app may crash on startup!");
                return;
            }

            if (string.IsNullOrEmpty(AppodealSettings.Instance.AdMobAndroidAppId))
            {
                if (CheckContainsAppId(path))
                {
                    androidManifest.RemoveAdmobAppId();
                }
                Debug.LogError(
                    $"Admob App ID is not set via 'Appodeal/Appodeal Settings' tool." +
                    "\nThe app may crash on startup!");
            }
            else
            {
                if (!AppodealSettings.Instance.AdMobAndroidAppId.StartsWith("ca-app-pub-"))
                {
                    Debug.LogError(
                        "Incorrect value. The app may crash on startup." +
                        "\nPlease enter a valid AdMob App ID via 'Appodeal/Appodeal Settings' tool.");
                }

                if (CheckContainsAppId(path))
                {
                    androidManifest.ChangeAdmobAppId(AppodealSettings.Instance.AdMobAndroidAppId);
                }
                else
                {
                    androidManifest.AddAdmobAppId(AppodealSettings.Instance.AdMobAndroidAppId);
                }
            }
        }