Platform-specific implementations for iOS, Android, macOS, tvOS, and devtools with native build system integration and cross-platform module resolution.
Dynamic loading of platform-specific linking implementations based on target platform.
/**
* Get platform-specific linking implementation
* @param platform - Target platform identifier
* @returns Platform-specific implementation module
* @throws Error if platform is not supported
*/
function getLinkingImplementationForPlatform(
platform: SupportedPlatform
): PlatformImplementation;
// Overloaded signatures for type safety
function getLinkingImplementationForPlatform(
platform: 'ios' | 'macos' | 'tvos' | 'apple'
): ApplePlatformImplementation;
function getLinkingImplementationForPlatform(
platform: 'android'
): AndroidPlatformImplementation;
function getLinkingImplementationForPlatform(
platform: 'devtools'
): DevToolsPlatformImplementation;Usage Examples:
import { getLinkingImplementationForPlatform } from "expo-modules-autolinking";
// Get iOS implementation
const iosImpl = getLinkingImplementationForPlatform("ios");
// Get Android implementation
const androidImpl = getLinkingImplementationForPlatform("android");
// Get DevTools implementation
const devtoolsImpl = getLinkingImplementationForPlatform("devtools");
// Error handling for unsupported platforms
try {
const unknownImpl = getLinkingImplementationForPlatform("unknown-platform");
} catch (error) {
console.error("Platform not supported:", error.message);
}iOS-specific module descriptor with Pod specifications and Swift module configuration.
interface ModuleDescriptorIos extends CommonNativeModuleDescriptor {
/** Swift native module class names */
modules: string[];
/** Pod specifications with directory information */
pods: ModuleIosPodspecInfo[];
/** Platform-specific flags and configuration */
flags: Record<string, any> | undefined;
/** Swift product module names for imports */
swiftModuleNames: string[];
/** AppDelegate lifecycle event subscribers */
appDelegateSubscribers: string[];
/** React delegate handler implementations */
reactDelegateHandlers: string[];
/** Whether module is debug-only */
debugOnly: boolean;
}
interface ModuleIosPodspecInfo {
/** Pod name in CocoaPods */
podName: string;
/** Directory containing podspec file */
podspecDir: string;
}Configuration options specific to Apple platforms (iOS, macOS, tvOS).
interface RawModuleConfigApple {
/** Swift native module class names */
modules?: string[];
/** AppDelegate lifecycle event subscriber class names */
appDelegateSubscribers?: string[];
/** React delegate handler class names */
reactDelegateHandlers?: string[];
/** Podspec relative path (string or array for multiple) */
podspecPath?: string | string[];
/** Swift product module name (string or array for multiple) */
swiftModuleName?: string | string[];
/** Whether module is debug-only (default: false) */
debugOnly?: boolean;
}
interface AppleCodeSignEntitlements {
/** App Groups entitlements for shared data access */
appGroups?: string[];
}Usage Examples:
// iOS module configuration
const iosModuleConfig: RawModuleConfigApple = {
modules: ["MyExpoModule", "MyOtherModule"],
appDelegateSubscribers: ["MyAppDelegateSubscriber"],
reactDelegateHandlers: ["MyReactDelegateHandler"],
podspecPath: ["MyModule.podspec", "MyOtherModule.podspec"],
swiftModuleName: ["MyModule", "MyOtherModule"],
debugOnly: false
};
// Debug-only module for development
const debugModuleConfig: RawModuleConfigApple = {
modules: ["DebugUtilities"],
podspecPath: "DebugUtilities.podspec",
debugOnly: true
};Android-specific module descriptor with Gradle project and plugin information.
interface ModuleDescriptorAndroid extends CommonNativeModuleDescriptor {
/** Gradle project configurations */
projects?: ModuleAndroidProjectInfo[];
/** Gradle plugin configurations */
plugins?: ModuleAndroidPluginInfo[];
}
interface ModuleAndroidProjectInfo {
/** Gradle project name */
name: string;
/** Source directory containing build.gradle */
sourceDir: string;
/** Android native module names */
modules: string[];
/** Maven publication information */
publication?: AndroidPublication;
/** AAR project descriptors */
aarProjects?: AndroidGradleAarProjectDescriptor[];
/** Script to determine publication usage */
shouldUsePublicationScriptPath?: string;
}
interface ModuleAndroidPluginInfo {
/** Gradle plugin ID */
id: string;
/** Source directory for plugin */
sourceDir: string;
}Comprehensive Android platform configuration with Gradle integration.
interface RawAndroidConfig {
/** Gradle project configurations */
projects?: Array<{
name: string;
path: string;
modules?: string[];
publication?: AndroidPublication;
gradleAarProjects?: AndroidGradleAarProjectDescriptor[];
shouldUsePublicationScriptPath?: string;
}>;
/** Gradle plugin descriptors */
gradlePlugins?: AndroidGradlePluginDescriptor[];
}
interface AndroidGradlePluginDescriptor {
/** Gradle plugin ID */
id: string;
/** Artifact group */
group: string;
/** Relative path to gradle plugin directory */
sourceDir: string;
/** Whether to apply to root project (default: true) */
applyToRootProject?: boolean;
}
interface AndroidGradleAarProjectDescriptor {
/** Gradle project name */
name: string;
/** Path to AAR file */
aarFilePath: string;
}Maven repository configuration with authentication support.
interface AndroidMavenRepository {
/** Maven repository URL */
url: string;
/** Repository access credentials */
credentials?: AndroidMavenRepositoryCredentials;
/** Authentication scheme */
authentication?: 'basic' | 'digest' | 'header';
}
type AndroidMavenRepositoryCredentials =
| AndroidMavenRepositoryPasswordCredentials
| AndroidMavenRepositoryHttpHeaderCredentials
| AndroidMavenRepositoryAWSCredentials;
interface AndroidMavenRepositoryPasswordCredentials {
username: string;
password: string;
}
interface AndroidMavenRepositoryHttpHeaderCredentials {
name: string;
value: string;
}
interface AndroidMavenRepositoryAWSCredentials {
accessKey: string;
secretKey: string;
sessionToken?: string;
}Usage Examples:
// Android module configuration
const androidConfig: RawAndroidConfig = {
projects: [
{
name: "my-expo-module",
path: "./android",
modules: ["MyExpoModule", "MyOtherModule"],
publication: {
id: "my-expo-module",
group: "com.mycompany",
version: "1.0.0",
repository: "https://maven.mycompany.com/releases"
}
}
],
gradlePlugins: [
{
id: "com.mycompany.expo-plugin",
group: "com.mycompany",
sourceDir: "./gradle-plugin",
applyToRootProject: true
}
]
};
// Maven repository with authentication
const mavenRepo: AndroidMavenRepository = {
url: "https://private-maven.company.com/releases",
credentials: {
username: "maven-user",
password: "maven-password"
},
authentication: "basic"
};DevTools-specific module descriptor for development tool integrations.
interface ModuleDescriptorDevTools {
/** Package name */
packageName: string;
/** Package root directory */
packageRoot: string;
/** Web resource root directory */
webpageRoot: string;
}Configuration for development tools integration.
interface DevToolsConfig {
/** Web resource root directory for CLI DevTools */
webpageRoot: string;
}Usage Examples:
// DevTools module configuration
const devtoolsConfig: DevToolsConfig = {
webpageRoot: "./web-resources"
};
// DevTools module descriptor
const devtoolsModule: ModuleDescriptorDevTools = {
packageName: "my-devtools-extension",
packageRoot: "/path/to/package",
webpageRoot: "/path/to/web-resources"
};Base interface shared across all platform-specific descriptors.
interface CommonNativeModuleDescriptor {
/** Package name identifier */
packageName: string;
/** Core features required by this module */
coreFeatures?: string[];
}
type ModuleDescriptor =
| ModuleDescriptorAndroid
| ModuleDescriptorIos
| ModuleDescriptorDevTools;type SupportedPlatform =
| 'apple' // Generic Apple platform
| 'ios' // iOS specific
| 'android' // Android specific
| 'web' // Web platform
| 'macos' // macOS specific
| 'tvos' // tvOS specific
| 'devtools' // Development tools
| (string & {}); // Allow custom platform stringsPlatform-specific extra dependencies for build systems.
type ExtraDependencies = AndroidMavenRepository[] | ApplePod[];
interface ApplePod {
name: string;
version?: string;
configurations?: string[];
modular_headers?: boolean;
source?: string;
path?: string;
podspec?: string;
testspecs?: string[];
git?: string;
branch?: string;
tag?: string;
commit?: string;
}Platform Detection Example:
import { getLinkingImplementationForPlatform, SupportedPlatform } from "expo-modules-autolinking";
function configureForPlatform(platform: SupportedPlatform) {
const impl = getLinkingImplementationForPlatform(platform);
switch (platform) {
case 'ios':
case 'macos':
case 'tvos':
case 'apple':
return configureApplePlatform(impl);
case 'android':
return configureAndroidPlatform(impl);
case 'devtools':
return configureDevToolsPlatform(impl);
default:
throw new Error(`Unsupported platform: ${platform}`);
}
}