diff --git a/forge-gui-android/pom.xml b/forge-gui-android/pom.xml index 6835c95c78f..9ded00084db 100644 --- a/forge-gui-android/pom.xml +++ b/forge-gui-android/pom.xml @@ -694,5 +694,136 @@ + + + android-dev-build + + forge.app.dev + apk + + + + forge-dev-android-${snapshot-version} + + + exec-maven-plugin + 3.4.1 + org.codehaus.mojo + + + SignV2 + verify + + exec + + + + + ${pom.basedir} + java + + -jar + ${pom.basedir}/tools/uber-apk-signer.jar + -a + ${pom.basedir}/target/ + --debug + + + + + com.simpligility.maven.plugins + android-maven-plugin + + + javax.xml.bind + jaxb-api + 2.3.1 + + + com.sun.xml.bind + jaxb-impl + 2.3.4 + + + sun + misc + 1 + system + ${pom.basedir}/libs/sun-misc.jar + + + 4.6.2 + true + + + false + + ${app.id.dev} + + ${androidPlatform} + ${androidBuildTools} + + + false + + true + ${project.basedir}/assets + ${project.basedir}/res + ${project.basedir}/libs + true + + false + ${project.basedir}/proguard.cfg + + ${pom.basedir}/tools/proguard.jar + true + d8 + + 26 + + ${build.min.memory} + ${build.max.memory} + + + + true + + ${build.min.memory} + ${build.max.memory} + + --min-sdk-version=26 + + + + + update-manifest + + manifest-merger + + + ${snapshot-version}-dev + + + + fix-provider-authorities + process-resources + + manifest-update + + + false + Forge (dev) + + ${app.id.dev}.SentryInitProvider + ${app.id.dev}.SentryPerformanceProvider + ${app.id.dev}.publicfileprovider + + + + + + + + diff --git a/forge-gui-android/src/forge/app/Main.java b/forge-gui-android/src/forge/app/Main.java index 490692d4d9c..a563ca5be69 100644 --- a/forge-gui-android/src/forge/app/Main.java +++ b/forge-gui-android/src/forge/app/Main.java @@ -90,6 +90,26 @@ public class Main extends AndroidApplication { private TextView progressText; private String versionString; + // The package name the resources are compiled under (stable across dev/prod). + // If you ever change the base app package, update this constant once. + private static final String RES_PKG_FALLBACK = "forge.app"; + + private int resId(String type, String name) { + // 1) Try fully-qualified with *runtime* package + int id = getResources().getIdentifier(name, type, getPackageName()); + if (id != 0) return id; + + // 2) Try fully-qualified with *fallback* resource package + if (!RES_PKG_FALLBACK.equals(getPackageName())) { + id = getResources().getIdentifier(name, type, RES_PKG_FALLBACK); + if (id != 0) return id; + } + + android.util.Log.e("ForgeRes", "Missing resource " + type + "/" + name + + " for pkg=" + getPackageName() + " (also tried " + RES_PKG_FALLBACK + ")"); + return 0; + } + private AndroidClipboard getAndroidClipboard() { if (androidClipboard == null) androidClipboard = new AndroidClipboard(); @@ -148,13 +168,13 @@ public class Main extends AndroidApplication { } catch (Exception e) { versionString = "0.0"; } - setContentView(getResources().getIdentifier("main", "layout", getPackageName())); + setContentView(resId("layout", "main")); mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime); sharedPreferences = getPreferences(Context.MODE_PRIVATE); - progressBar = findViewById(getResources().getIdentifier("pBar", "id", getPackageName())); + progressBar = findViewById(resId("id", "pBar")); progressBar.setIndeterminate(true); progressBar.setVisibility(View.GONE); - progressText = findViewById(getResources().getIdentifier("pText", "id", getPackageName())); + progressText = findViewById(resId("id", "pText")); progressText.setVisibility(View.GONE); isMIUI = isMiUi(); @@ -308,8 +328,8 @@ public class Main extends AndroidApplication { private void loadGame(final String title, final String steps, boolean isLandscape, AndroidAdapter adapter, boolean permissiongranted, int totalRAM, boolean isTabletDevice, AndroidApplicationConfiguration config, boolean exception, String msg) { try { final Handler handler = new Handler(); - forgeLogo = findViewById(getResources().getIdentifier("logo_id", "id", getPackageName())); - activeView = findViewById(getResources().getIdentifier("mainview", "id", getPackageName())); + forgeLogo = findViewById(resId("id", "logo_id")); + activeView = findViewById(resId("id", "mainview")); activeView.setBackgroundColor(Color.WHITE); forgeView = initializeForView(Forge.getApp(getAndroidClipboard(), adapter, ASSETS_DIR, false, !isLandscape, totalRAM, isTabletDevice, Build.VERSION.SDK_INT, Build.VERSION.RELEASE, getDeviceName()), config); @@ -674,6 +694,11 @@ public class Main extends AndroidApplication { return new GitLogs().getLatestReleaseTag(releaseAtom); } + private String fileProviderAuthority() { + // Works for both prod (forge.app) and dev (forge.app.dev) + return getPackageName() + ".publicfileprovider"; + } + @Override public boolean openFile(String filename) { try { @@ -688,7 +713,8 @@ public class Main extends AndroidApplication { return true; } else { Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE); - intent.setData(PublicFileProvider.getUriForFile(getContext(), "com.mydomain.publicfileprovider", new File(filename))); + intent.setData(PublicFileProvider.getUriForFile( + getContext(), fileProviderAuthority(), new File(filename))); intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(intent); return true;