Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not find path for Manifest and incorrect build path on build for android #49

Open
bobanminic96 opened this issue Aug 14, 2020 · 0 comments

Comments

@bobanminic96
Copy link

Ok, so i had this two issues.

Both fixed in Build.cs . In comments after // ... it is version which was before changes!

public static void DoBuildAndroid()
{
string buildPath = Path.Combine(apkPath); // -not working version Path.Combine(apkPath, Application.productName);
string exportPath = Path.GetFullPath(Path.Combine(ProjectPath, "../../android/UnityExport"));

    if (Directory.Exists(apkPath))
        Directory.Delete(apkPath, true);

    if (Directory.Exists(exportPath))
        Directory.Delete(exportPath, true);

    EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle;

    var options = BuildOptions.AcceptExternalModificationsToPlayer;
    var report = BuildPipeline.BuildPlayer(
        GetEnabledScenes(),
        apkPath,
        BuildTarget.Android,
        options
    );

    if (report.summary.result != BuildResult.Succeeded)
        throw new Exception("Build failed");

    Copy(buildPath, exportPath);

    // Modify build.gradle
	var build_file = Path.Combine(exportPath, "build.gradle");
	var build_text = File.ReadAllText(build_file);
	build_text = build_text.Replace("com.android.application", "com.android.library");
    build_text = build_text.Replace("implementation fileTree(dir: 'libs', include: ['*.jar'])", "api fileTree(include: ['*.jar'], dir: 'libs')");
    // build_text = build_text.Replace("implementation(name: 'VuforiaWrapper', ext:'aar')", "api(name: 'VuforiaWrapper', ext: 'aar')");
	build_text = Regex.Replace(build_text, @"\n.*applicationId '.+'.*\n", "\n");
	File.WriteAllText(build_file, build_text);

    // Modify AndroidManifest.xml
    var manifest_file = Path.Combine(exportPath, "unityLibrary/src/main/AndroidManifest.xml"); //   -not working version, missed 'unityLibrary/' + src/main/AndroidManifest.xml");
    var manifest_text = File.ReadAllText(manifest_file);
    manifest_text = Regex.Replace(manifest_text, @"<application .*>", "<application>");
    Regex regex = new Regex(@"<activity.*>(\s|\S)+?</activity>", RegexOptions.Multiline);
    manifest_text = regex.Replace(manifest_text, "");
    File.WriteAllText(manifest_file, manifest_text);
}

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant