react-native-agora icon indicating copy to clipboard operation
react-native-agora copied to clipboard

Build fails with Android SDK 31

Open radko93 opened this issue 3 years ago • 13 comments

Error:

Error:
	android:exported needs to be explicitly specified for <service>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

I found it's agora using this answer. Generated manifest (see it's missing exported for activity and service):

<activity
            android:name="io.agora.rtc.ss.impl.ScreenSharing$LocalScreenCaptureAssistantActivity"
            android:configChanges="screenSize|orientation"
            android:screenOrientation="fullUser"
            android:theme="@android:style/Theme.Translucent" />

        <service
            android:name="io.agora.rtc.ss.impl.LocalScreenSharingService"
            android:foregroundServiceType="mediaProjection" >
            <intent-filter>
                <action android:name="android.intent.action.screenshare" />
            </intent-filter>
        </service>

Patch (add this to your manifest):

<activity android:name="io.agora.rtc.ss.impl.ScreenSharing$LocalScreenCaptureAssistantActivity"
            android:exported="false"
            tools:node="merge" />
<service
    android:name="io.agora.rtc.ss.impl.LocalScreenSharingService"
    android:exported="false"
    android:foregroundServiceType="mediaProjection" tools:node="merge" />

radko93 avatar May 13 '22 20:05 radko93

I just came here following a similar path. Took a while to find the culprit and the solution. Thanks for posting!

I added:

<service android:exported="true" android:foregroundServiceType="mediaProjection" android:name="io.agora.rtc.ss.impl.LocalScreenSharingService"> <intent-filter> <action android:name="android.intent.action.screenshare"/> </intent-filter> </service>

akenger avatar May 13 '22 21:05 akenger

@LichKing-2234 I can confirm the above issue. Can we update the SDK to avoid this workaround while building the app for Android SDK 31?

EkaanshArora avatar May 18 '22 13:05 EkaanshArora

It will be fixed in the next version. You can use the workaround before.

LichKing-2234 avatar May 27 '22 09:05 LichKing-2234

Where to put the service tag in manifest in agora manifest or app manifest?

ohowajiha avatar Jun 08 '22 12:06 ohowajiha

@ohowajiha your app manifest

radko93 avatar Jun 10 '22 07:06 radko93

Hi there.

any update?

is there a solution for Expo EAS Build (Managed App)? with the same error message.

image

OR how to fix this error at Runtime (without Rebuilding Expo Managed App)?

image

kuriel-trivu avatar Jun 20 '22 15:06 kuriel-trivu

You can patch-package the build.gradle file to point at the more recent AAR with the fix, which is an approach that's compatible with Expo's managed workflow. Below is the react-native-agora+3.7.0.patch file to use with patch-package:

diff --git a/node_modules/react-native-agora/android/build.gradle b/node_modules/react-native-agora/android/build.gradle
index 5e66c96..9f5a1bf 100644
--- a/node_modules/react-native-agora/android/build.gradle
+++ b/node_modules/react-native-agora/android/build.gradle
@@ -128,7 +128,7 @@ dependencies {
   // noinspection GradleDynamicVersion
   api 'com.facebook.react:react-native:+'
   api 'io.agora.rtc:full-sdk:3.7.0'
-  implementation 'io.agora.rtc:full-screen-sharing:3.7.0'
+  implementation 'io.agora.rtc:full-screen-sharing:3.7.0.204.1'
 
   implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
 }

kbrandwijk avatar Jun 24 '22 22:06 kbrandwijk

A million thanks to @kbrandwijk and @EkaanshArora for their input, feedback, and support.

I can now finally build the Expo native client for Android with the following BASH script that creates a brand-new Expo project, installs the NPMs, patches react-native-agora, then runs the EAS Build.

rm -rf repro-1101

expo init --npm -t blank repro-1101
cd repro-1101

# install Expo libs
#
expo install expo-dev-client
expo install react-native-agora agora-rn-uikit agora-react-native-rtm

# have to patch react-native-agora to fix Issue 1101
#
npm install -D patch-package

mkdir patches
cat <<EOF > patches/react-native-agora+3.7.0.patch
diff --git a/node_modules/react-native-agora/android/build.gradle b/node_modules/react-native-agora/android/build.gradle
index 5e66c96..9f5a1bf 100644
--- a/node_modules/react-native-agora/android/build.gradle
+++ b/node_modules/react-native-agora/android/build.gradle
@@ -128,7 +128,7 @@ dependencies {
   // noinspection GradleDynamicVersion
   api 'com.facebook.react:react-native:+'
   api 'io.agora.rtc:full-sdk:3.7.0'
-  implementation 'io.agora.rtc:full-screen-sharing:3.7.0'
+  implementation 'io.agora.rtc:full-screen-sharing:3.7.0.204.1'

   implementation "org.jetbrains.kotlin:kotlin-stdlib:\$kotlin_version"
 }
EOF

# add postinstall script to package.json
#
npm install -D json
$(npm bin)/json -I -f package.json -e "this.scripts.postinstall=\"patch-package\""

# apply the patch
#
npm install

# do EAS Build
#
eas build:configure -p all
eas build -p android --profile development

set +x
echo "done"

gregfenton avatar Jun 25 '22 02:06 gregfenton

I had to update manually

/node_modules/react-native-agora/android/build.gradle

because got some errors from patch-package.

Just changed:

implementation 'io.agora.rtc:full-screen-sharing:3.7.0' <-- this
implementation 'io.agora.rtc:full-screen-sharing:3.7.0.204.1' <-- by this one

after that i run

npx patch-package react-native-agora

then build with EAS and everything works!!

kuriel-trivu avatar Jun 25 '22 07:06 kuriel-trivu

The fix from @kuriel-trivu solves it for me as well - I took the liberty of opening a PR with the suggested changes.

DJ-Icebear avatar Jun 30 '22 14:06 DJ-Icebear

The reason I patched, instead of PR'd, was because it was mentioned in this comment that it would already be fixed in the next version: https://github.com/AgoraIO-Community/react-native-agora/issues/496#issuecomment-1139433362

kbrandwijk avatar Jul 01 '22 01:07 kbrandwijk

@LichKing-2234 is this fixed now?

radko93 avatar Oct 03 '22 13:10 radko93

I think the 3.7.1 version has fixed it.

LichKing-2234 avatar Oct 13 '22 03:10 LichKing-2234