expo-keystore-manager
Version:
A comprehensive Expo config plugin for managing Android release keystore configuration
84 lines (75 loc) • 3.02 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const config_plugins_1 = require("@expo/config-plugins");
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
/**
* Adds ProGuard configuration for release builds
*/
const withProguardConfig = (config, options = {}) => {
if (!options.enableProguard) {
return config;
}
return (0, config_plugins_1.withDangerousMod)(config, [
"android",
async (config) => {
const projectRoot = config.modRequest.projectRoot;
const androidProjectRoot = path_1.default.join(projectRoot, "android");
const appRoot = path_1.default.join(androidProjectRoot, "app");
const proguardRulesPath = path_1.default.join(appRoot, "proguard-rules.pro");
// Create default ProGuard rules if they don't exist
if (!fs_1.default.existsSync(proguardRulesPath)) {
const defaultProguardRules = `# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
# React Native specific rules
-keep class com.facebook.react.** { *; }
-keep class com.facebook.hermes.** { *; }
-keep class com.facebook.jni.** { *; }
# Expo specific rules
-keep class expo.** { *; }
-keep class versioned.host.exp.exponent.** { *; }
# Keep native methods
-keepclasseswithmembernames class * {
native <methods>;
}
# Keep custom application class
-keep public class * extends android.app.Application
# Keep serializable classes
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
# Custom rules from plugin options
${options.customProguardRules || ""}
`;
fs_1.default.writeFileSync(proguardRulesPath, defaultProguardRules);
}
return config;
},
]);
};
exports.default = withProguardConfig;
//# sourceMappingURL=withProguardConfig.js.map