public virtual void CopyJavaFilesAndReplacePackageName(string RootSourceDir, string RootDestDir) { List <string> JavaFilesToCopy = IgorRuntimeUtils.GetListOfFilesAndDirectoriesInDirectory(RootSourceDir, true, false, true, true, true); foreach (string CurrentFile in JavaFilesToCopy) { if (CurrentFile.EndsWith(".java") || CurrentFile.EndsWith(".aidl")) { string RelativeFilePath = CurrentFile.Substring(RootSourceDir.Length + 1); string NewDestinationPath = Path.Combine(RootDestDir, RelativeFilePath); if (!Directory.Exists(Path.GetDirectoryName(NewDestinationPath))) { Directory.CreateDirectory(Path.GetDirectoryName(NewDestinationPath)); } if (!File.Exists(NewDestinationPath)) { IgorRuntimeUtils.CopyFile(CurrentFile, NewDestinationPath); IgorUtils.ReplaceStringsInFile(this, NewDestinationPath, "com.facebook.android.R", PlayerSettings.bundleIdentifier + ".R"); IgorUtils.ReplaceStringsInFile(this, NewDestinationPath, "import com.facebook.android.*;", "import com.facebook.android.*;\nimport " + PlayerSettings.bundleIdentifier + ".R;"); IgorUtils.ReplaceStringsInFile(this, NewDestinationPath, "com.facebook.android.BuildConfig", PlayerSettings.bundleIdentifier + ".BuildConfig"); IgorUtils.ReplaceStringsInFile(this, NewDestinationPath, "import com.mikamikem.AndroidUnity.R;", "import " + PlayerSettings.bundleIdentifier + ".R;"); } } } }
public static string GetZipAlignPath(IIgorModule ModuleInst) { string AndroidSDKPath = GetAndroidSDKPath(ModuleInst); string ZipAlignPath = ""; if (IgorAssert.EnsureTrue(ModuleInst, Directory.Exists(AndroidSDKPath), "The Android SDK path " + AndroidSDKPath + " doesn't exist!")) { string BuildToolsPath = Path.Combine(AndroidSDKPath, "build-tools"); if (IgorAssert.EnsureTrue(ModuleInst, Directory.Exists(BuildToolsPath), "The Android build tools path " + BuildToolsPath + " doesn't exist!")) { List <string> BuildToolVersions = IgorRuntimeUtils.GetListOfFilesAndDirectoriesInDirectory(BuildToolsPath, false, true, false, true, true); foreach (string CurrentVersion in BuildToolVersions) { string ZipAlignVersionPath = Path.Combine(BuildToolsPath, Path.Combine(CurrentVersion, "zipalign")); if (File.Exists(ZipAlignVersionPath)) { ZipAlignPath = ZipAlignVersionPath; break; } } IgorAssert.EnsureTrue(ModuleInst, ZipAlignPath != "", "ZipAlign couldn't be found! Have you downloaded the android build-tools?"); } } return(ZipAlignPath); }
// This is necessary as of 5.x If the 3rd party libraries that you include are marked read only (like when you use Perforce as a version control system) // your build will fail in the built-in Unity postprocess step, so we just set them all to read/write before we build. public static void FixReadOnlyFilesIn3rdPartyLibs() { string AndroidPluginPathRoot = Path.Combine(Path.GetFullPath("."), Path.Combine("Assets", Path.Combine("Plugins", "Android"))); List <string> Android3rdPartyLibFiles = IgorRuntimeUtils.GetListOfFilesAndDirectoriesInDirectory(AndroidPluginPathRoot, true, false, true); foreach (string CurrentFilePath in Android3rdPartyLibFiles) { string CurrentFullPath = Path.Combine(AndroidPluginPathRoot, CurrentFilePath); if (File.Exists(CurrentFullPath)) { File.SetAttributes(CurrentFullPath, System.IO.FileAttributes.Normal); } } }
public virtual void CopyLauncherToProjectPath(BuildTarget TargetTestPlatform, string TempPath, string LocalPath) { if (TargetTestPlatform == BuildTarget.StandaloneOSXIntel64) { string ZipPath = Path.Combine(TempPath, "MonsterLauncherOSX.zip"); List <string> ZipFileList = new List <string>(); foreach (string FilePath in IgorRuntimeUtils.GetListOfFilesAndDirectoriesInDirectory(Path.Combine(TempPath, "MonsterLauncher.app"), true, false, true)) { ZipFileList.Add("MonsterLauncher.app/" + FilePath); } IgorZip.ZipFilesCrossPlatform(this, ZipFileList, ZipPath, false, TempPath); string ZipLocalPath = Path.Combine(LocalPath, "MonsterLauncherOSX.zip"); if (File.Exists(ZipLocalPath)) { IgorRuntimeUtils.DeleteFile(ZipLocalPath); } IgorRuntimeUtils.CopyFile(ZipPath, ZipLocalPath); } else if (TargetTestPlatform == BuildTarget.StandaloneWindows64) { string ZipPath = Path.Combine(TempPath, "MonsterLauncherWindows.zip"); List <string> ZipFileList = new List <string>(); foreach (string FilePath in IgorRuntimeUtils.GetListOfFilesAndDirectoriesInDirectory(Path.Combine(TempPath, "MonsterLauncher_Data"), true, false, true)) { ZipFileList.Add("MonsterLauncher_Data/" + FilePath); } ZipFileList.Add("MonsterLauncher.exe"); IgorZip.ZipFilesCrossPlatform(this, ZipFileList, ZipPath, false, TempPath); string ZipLocalPath = Path.Combine(LocalPath, "MonsterLauncherWindows.zip"); if (File.Exists(ZipLocalPath)) { IgorRuntimeUtils.DeleteFile(ZipLocalPath); } IgorRuntimeUtils.CopyFile(ZipPath, ZipLocalPath); } }
public static bool ResignAPK(IIgorModule ModuleInst, string SourceAPK, string RepackagingDirectory, ref string FinalFilename, string KeystoreFilename, string KeystorePassword, string KeyAlias, string KeyAliasPassword) { if (Directory.Exists(RepackagingDirectory)) { IgorRuntimeUtils.DeleteDirectory(RepackagingDirectory); } Directory.CreateDirectory(RepackagingDirectory); IgorZip.UnzipArchiveCrossPlatform(ModuleInst, SourceAPK, RepackagingDirectory); IgorRuntimeUtils.DeleteDirectory(Path.Combine(RepackagingDirectory, "META-INF")); string UnsignedAPK = Path.Combine(RepackagingDirectory, "Repackaged.unsigned.apk"); List <string> APKContents = IgorRuntimeUtils.GetListOfFilesAndDirectoriesInDirectory(RepackagingDirectory); IgorZip.ZipFilesCrossPlatform(ModuleInst, APKContents, UnsignedAPK, false, RepackagingDirectory); string SignedAPK = Path.Combine(RepackagingDirectory, "Repackaged.signed.apk"); // IgorCore.LogError(ModuleInst, "jarsigner command running from " + Path.GetFullPath(".") + " is\n" + "-verbose -keystore \"" + KeystoreFilename + "\" -storepass " + KeystorePassword + // " -keypass " + KeyAliasPassword + " -signedjar \"" + SignedAPK + "\" \"" + UnsignedAPK + "\" " + KeyAlias); if (IgorRuntimeUtils.RunProcessCrossPlatform(ModuleInst, "jarsigner", "jarsigner", "-verbose -sigalg SHA1withDSA -digestalg SHA1 -keystore \"" + KeystoreFilename + "\" -storepass " + KeystorePassword + " -keypass " + KeyAliasPassword + " -signedjar \"" + SignedAPK + "\" \"" + UnsignedAPK + "\" " + KeyAlias, Path.GetFullPath("."), "Running jarsigner", true) != 0) { return(false); } string ZipAlignPath = GetZipAlignPath(ModuleInst); string AlignedAPK = Path.Combine(RepackagingDirectory, "Repackaged.aligned.apk"); if (IgorRuntimeUtils.RunProcessCrossPlatform(ModuleInst, ZipAlignPath, ZipAlignPath, "-v 4 \"" + SignedAPK + "\" \"" + AlignedAPK + "\"", Path.GetFullPath("."), "Running zipalign") != 0) { return(false); } FinalFilename = AlignedAPK; return(true); }