admin 管理员组

文章数量: 1086019

I'm developing a Nitro Modules native module to integrate an Android SDK into an Expo React Native app. I've successfully created mock functions with the correct typings, but I'm facing issues importing the .AAR SDK and setting up Dagger Hilt for dependency injection.

Here are the key issues I'm running into:

Manifest Configuration – The SDK requires initialization on device boot via a receiver in AndroidManifest.xml. Should this be added to the Nitro Modules manifest or the Expo prebuild manifest?

Dagger Hilt Dependency Injection – The SDK requires Hilt for proper instantiation, but I'm unsure how to set it up within the Nitro Modules ecosystem to avoid runtime errors.

AAR Import Issues – The .AAR file is placed inside the /android/libs/ directory of the Nitro Modules project, but Expo doesn’t seem to import it. As a workaround, I’ve been manually copying it to node_modules, which is not ideal.

What I’ve Tried

  1. Added implementation(files("path_to/AndroidSDK.aar")) to build.gradle from Nitro Modules.

  2. Placed the receiver in AndroidManifest.xml inside the Nitro Modules project.

  3. Attempted to configure Hilt inside the Nitro module but faced issues during build.

  4. Tried adding 'tools:replace="android:name"' in both manifests.

After placing the receiver and application setup in AndroidManifest.xml from Nitro Modules I got merge failed errors after running npx expo run:android. Some like this:

Manifest merger failed : Attribute application@name value=(com.vitrr.example.MainApplication) from AndroidManifest.xml:17:16-47
    is also present at [:sdk] AndroidManifest.xml:11:9-69 value=(com.margelo.nitro.sdk.SdkBehaviorApp).
    Suggestion: add 'tools:replace="android:name"' to <application> element at AndroidManifest.xml:6:5-162 to override.

SdkBehaviorApp is the hilt factory class.

This is how my AndroidManifest.xml from Nitro Module looks like

<manifest xmlns:android=";>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application 
    android:name=".SdkBehaviorApp" >
    <receiver
        android:name="br.sdk.BootReceiver"
        android:enabled="true"
        android:exported="true"
        tools:ignore="ExportedReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            <!-- For HTC devices -->
            <action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
            <!-- When a new version of the app is installed over the existing one. -->
            <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>
    
</application>

Has anyone successfully integrated an .AAR SDK with Dagger Hilt into a Nitro Modules native module for Expo? Any guidance on properly importing the AAR and configuring Hilt in this context would be greatly appreciated!

本文标签: androidIssues Importing an AAR SDK in a Nitro Modules Native Module for ExpoStack Overflow