public override void fixProblem() { //EditorApplication.applicationContentsPath is different for macos and win. need to fix to reach manifest and gradle templates string defaultGradleTemplateFullName = MultidexActivator.getDefaultGradleTemplate(); string destGradleScriptFullName = AppodealUnityUtils.combinePaths(Application.dataPath, MultidexActivator.androidPluginsPath, MultidexActivator.gradleTemplateName); //Prefer to use build.gradle from the box. Just in case. if (File.Exists(defaultGradleTemplateFullName)) { File.Copy(defaultGradleTemplateFullName, destGradleScriptFullName); } AssetDatabase.ImportAsset(AppodealUnityUtils.absolute2Relative(destGradleScriptFullName), ImportAssetOptions.ForceUpdate); //There are no multidex settings in default build.gradle but they can add that stuff. ImportantGradleSettings settings = new ImportantGradleSettings(destGradleScriptFullName); if (!settings.isMultiDexAddedCompletely()) { new EnableMultidexInGradle(destGradleScriptFullName).fixProblem(); } }
public override void fixProblem() { ImportantGradleSettings settings = new ImportantGradleSettings(path); string leadingWhitespaces = ""; string line; string prevLine = ""; string modifiedGradle = ""; StreamReader gradleScript = new StreamReader(path); string multidexDependency; int comparsionUnityVersionWith20182 = AppodealUnityUtils.compareVersions(Application.unityVersion, "2018.2"); if (comparsionUnityVersionWith20182 < 0) { multidexDependency = MultidexActivator.GRADLE_COMPILE + MultidexActivator.GRADLE_MULTIDEX_DEPENDENCY; } else { multidexDependency = MultidexActivator.GRADLE_IMPLEMENTATION + MultidexActivator.GRADLE_MULTIDEX_DEPENDENCY; } while ((line = gradleScript.ReadLine()) != null) { if (!settings.multidexDependencyPresented && line.Contains(MultidexActivator.GRADLE_DEPENDENCIES)) { modifiedGradle += leadingWhitespaces + multidexDependency + Environment.NewLine; } if (!settings.multidexEnabled && line.Contains(MultidexActivator.GRADLE_APP_ID)) { modifiedGradle += leadingWhitespaces + MultidexActivator.GRADLE_MULTIDEX_ENABLE + Environment.NewLine; } if (settings.deprecatedProguardPresented && line.Contains(MultidexActivator.GRADLE_USE_PROGUARD)) { //useProguard is deprecated continue; } modifiedGradle += line + Environment.NewLine; leadingWhitespaces = Regex.Match(line, "^\\s*").Value; if (line.Contains("repositories") && prevLine.Contains("allprojects") && !settings.googleRepositoryPresented) { leadingWhitespaces += leadingWhitespaces; modifiedGradle += leadingWhitespaces + MultidexActivator.GRADLE_GOOGLE_REPOSITORY_COMPAT + Environment.NewLine; } prevLine = line; } gradleScript.Close(); File.WriteAllText(path, modifiedGradle); AssetDatabase.ImportAsset(AppodealUnityUtils.absolute2Relative(path), ImportAssetOptions.ForceUpdate); }
public override void fixProblem() { ImportantGradleSettings settings = new ImportantGradleSettings(path); string leadingWhitespaces = " "; string additionalWhiteSpaces = ""; string line; string modifiedGradle = ""; StreamReader gradleScript = new StreamReader(path); while ((line = gradleScript.ReadLine()) != null) { if (line.Contains(MultidexActivator.GRAFLE_DEFAULT_CONFIG)) { if (!settings.compileOptions) { modifiedGradle += additionalWhiteSpaces + leadingWhitespaces + MultidexActivator.COMPILE_OPTIONS + Environment.NewLine; } if (!settings.sourceCapability) { modifiedGradle += leadingWhitespaces + leadingWhitespaces + MultidexActivator.GRADLE_SOURCE_CAPABILITY + MultidexActivator.GRADLE_JAVA_VERSION_1_8 + Environment.NewLine; } if (!settings.targetCapability) { modifiedGradle += leadingWhitespaces + leadingWhitespaces + MultidexActivator.GRADLE_TARGET_CAPATILITY + MultidexActivator.GRADLE_JAVA_VERSION_1_8 + Environment.NewLine; } if (!settings.targetCapability) { modifiedGradle += leadingWhitespaces + "}" + Environment.NewLine; } if (!settings.targetCapability) { modifiedGradle += leadingWhitespaces + Environment.NewLine; } } modifiedGradle += line + Environment.NewLine; leadingWhitespaces = Regex.Match(line, "^\\s*").Value; } gradleScript.Close(); File.WriteAllText(path, modifiedGradle); AssetDatabase.ImportAsset(AppodealUnityUtils.absolute2Relative(path), ImportAssetOptions.ForceUpdate); }
static bool isMultidexEnabledSimpleCheck() { string path = getCustomGradleScriptPath(); if (string.IsNullOrEmpty(path)) { return(false); } ImportantGradleSettings settings = new ImportantGradleSettings(path); return(settings.isMultidexEnabled() && AppodealUnityUtils.isGradleEnabled()); }
public override void fixProblem() { var defaultGradleTemplateFullName = MultidexActivator.getDefaultGradleTemplate(); var destGradleScriptFullName = AppodealUnityUtils.combinePaths(Application.dataPath, MultidexActivator.androidPluginsPath, MultidexActivator.gradleTemplateName); if (File.Exists(defaultGradleTemplateFullName)) { File.Copy(defaultGradleTemplateFullName, destGradleScriptFullName); } AssetDatabase.ImportAsset(AppodealUnityUtils.absolute2Relative(destGradleScriptFullName), ImportAssetOptions.ForceUpdate); var settings = new ImportantGradleSettings(destGradleScriptFullName); if (!settings.isMultiDexAddedCompletely()) { new EnableMultidexInGradle(destGradleScriptFullName).fixProblem(); } }
override public List <FixProblemInstruction> check() { List <FixProblemInstruction> instructions = new List <FixProblemInstruction>(); if (isNodexBuild() && EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android) { if (!AppodealUnityUtils.isGradleEnabled()) { if (!AppodealUnityUtils.isGradleAvailable()) { FixProblemInstruction fix = new FixProblemInstruction( "Gradle should be enabled if you use nodex version of Appodeal Plugin. " + "But your version of Unity doesn't support gradle build system.Please update your Unity or use export to Eclipse or Android Studio.", false); instructions.Add(fix); return(instructions); } else { instructions.Add(new EnableGradle()); } } string customGradeScript = getCustomGradleScriptPath(); if (string.IsNullOrEmpty(customGradeScript) || !File.Exists(customGradeScript)) { if (File.Exists(getDefaultGradleTemplate())) { instructions.Add(new CopyGradleScriptAndEnableMultidex()); } else { FixProblemInstruction instr = new FixProblemInstruction( "Tere is no build.gradle template in your Unity. " + "Please ensure that your copy of Unity isn't crashed and contact Appodeal Support team.", false); instructions.Add(instr); return(instructions); } } else { ImportantGradleSettings settings = new ImportantGradleSettings(customGradeScript); if (!settings.isMultiDexAddedCompletely()) { instructions.Add(new EnableMultidexInGradle(customGradeScript)); } if (!settings.isJavaVersionIncluded()) { instructions.Add(new EnableJavaVersion(customGradeScript)); } } string customManifestPath = getCustomManifestPath(); if (string.IsNullOrEmpty(customManifestPath) || !File.Exists(customManifestPath)) { instructions.Add(new CopyManifestTemplateAndAddNameAttribute()); } else { XmlElement appNode = getApplicationNode(customManifestPath); string ns = appNode.GetNamespaceOfPrefix("android"); if (!appNode.HasAttribute("name", ns)) { instructions.Add(new AddNameAttrubute(appNode, ns)); } else { if (appNode.GetAttribute("name", ns) != manifestMutlidexApp) { FixProblemInstruction fix = new FixProblemInstruction( "We found that you use custom Application class in this project. " + "Please ensure that your application class meets the multidex requirements (see the official android multiex documentation).", false); instructions.Add(fix); } } } } else if (!isNodexBuild() && isMultidexEnabledSimpleCheck() && EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android) { FixProblemInstruction fix = new FixProblemInstruction( "We found that multidex is enabled in your project. To avoid possible problems please " + "replace current version of Appodeal plugin with nodex version.", false); instructions.Add(fix); } return(instructions); }