PhilipsHue / flutter_reactive_ble

Flutter library that handles BLE operations for multiple devices.
https://developers.meethue.com/
Other
667 stars 331 forks source link

Build against Android 30 SDK Fails #410

Closed pgiacomo69 closed 3 years ago

pgiacomo69 commented 3 years ago

Build against Android 30 SDK Fails

To Reproduce Steps to reproduce the behavior:

  1. Upgrade Package to 5.0.0 in project
  2. Build Against SDK 30, with minimum sdk 24
  3. Build fails with this message:
Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':app:bundleGooglePlayReleaseResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.Aapt2ProcessResourcesRunnable
   > Android resource linking failed
     ERROR:D:\Flutter\........\build\app\intermediates\bundle_manifest\googlePlayRelease\AndroidManifest.xml:35: AAPT: error: attribute android:usesPermissionFlags not found.
Taym95 commented 3 years ago

I dont think this is a library issue, you are having an Android resource linking failed issue, can you build our example app and check if you get this issue?

pgiacomo69 commented 3 years ago

Ok, later I can try. But yesterday I tried also to build my app against sdk 31 ad it worked. This is strange, it seems like this attribute works only with latest SDK, and it should not be included in manifest when building for SDK 30. Obviously, using the package version 4.0.1, the app is built normally.

Taym95 commented 3 years ago

error: attribute android:usesPermissionFlags not found, you should not add API 31+ permissions to app on API30, example: <uses-permission android:name="android.permission.BLUETOOTH_SCAN"android:usesPermissionFlags="neverForLocation" /> works only on API >= 31

pgiacomo69 commented 3 years ago

error: attribute android:usesPermissionFlags not found, you should not add API 31+ permissions to app on API30, example: <uses-permission android:name="android.permission.BLUETOOTH_SCAN"android:usesPermissionFlags="neverForLocation" /> works only on API >= 31

Yes, but this line comes from package

PieterAelse commented 3 years ago

android:usesPermissionFlags="neverForLocation" is added to the Manifest of the Example app (see link), but it is not setup in our package, see the manifest.xml here.

So @pgiacomo69 are you sure you didn't set it up yourself in your manifest file?

pgiacomo69 commented 3 years ago

No way, this is my manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="it.seleuco.unical_cr_app">
    <uses-feature android:name="android.hardware.bluetooth"/>
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <!-- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <application android:label="My App" android:icon="@mipmap/ic_launcher">
        <activity android:name=".MainActivity" android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme"/>
            <!-- Displays an Android View that continues showing the launch screen
                 Drawable until Flutter paints its first frame, then this splash
                 screen fades out. A splash screen is useful to avoid any visual
                 gap between the end of Android's launch screen and the painting of
                 Flutter's first frame. -->
            <meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable" android:resource="@drawable/launch_background"/>
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data android:name="flutterEmbedding" android:value="2"/>
    </application>

</manifest>
remonh87 commented 3 years ago

@PieterAelse I can confirm the issue. Just create an example app, add reactive ble and you see it. What Android is doing is adding the following in the merged manifest:

    <uses-permission
        android:name="android.permission.BLUETOOTH_SCAN"
        android:usesPermissionFlags="neverForLocation" />

šŸ¤¦

pgiacomo69 commented 3 years ago

@PieterAelse I can confirm the issue. Just create an example app, add reactive ble and you see it. What Android is doing is adding the following in the merged manifest:

    <uses-permission
        android:name="android.permission.BLUETOOTH_SCAN"
        android:usesPermissionFlags="neverForLocation" />

šŸ¤¦

Yessssss, now I was going crazy searching in other Packages

Taym95 commented 3 years ago

I managed to make it work by adding tools:node="remove" to:

 <uses-permission
            android:name="android.permission.BLUETOOTH_SCAN"
            android:usesPermissionFlags="neverForLocation" tools:node="remove" />

don't forgot to add xmlns:tools="http://schemas.android.com/tools" in the top of your manifest.

@remonh87 If this is okay I can add it as doc in readme!

pgiacomo69 commented 3 years ago

I managed to make it work by adding tools:node="remove" to:

 <uses-permission
            android:name="android.permission.BLUETOOTH_SCAN"
            android:usesPermissionFlags="neverForLocation" tools:node="remove" />

don't forgot to add xmlns:tools="http://schemas.android.com/tools" in the top of your manifest.

@remonh87 If this is okay I can add it as doc in readme!

But this should be used only with sdk<31? Iā€™m curious to understand why this attribute is automagically set in sdk 30, and by who?

Taym95 commented 3 years ago

I managed to make it work by adding tools:node="remove" to:

 <uses-permission
            android:name="android.permission.BLUETOOTH_SCAN"
            android:usesPermissionFlags="neverForLocation" tools:node="remove" />

don't forgot to add xmlns:tools="http://schemas.android.com/tools" in the top of your manifest. @remonh87 If this is okay I can add it as doc in readme!

But this should be used only with sdk<31? Iā€™m curious to understand why this attribute is automagically set in sdk 30, and by who?

Yes should be used only with sdk<31

remonh87 commented 3 years ago

yep that works for me lets do this! thanks @Taym95 . šŸŽ‰

safield commented 3 years ago

I have this same problem. What is the correct course of action? Is there a fix incoming?

Taym95 commented 3 years ago

I have this same problem. What is the correct course of action? Is there a fix incoming?

The solution in mentioned in the PR and in the comment above šŸ‘†

YellowShark commented 3 years ago

you should set Android SDK 31

farr64 commented 2 years ago

@YellowShark mentioned:

you should set Android SDK 31

Would this be a more fundamental solution? After all, flutter doctor asserts:

[āœ“] Android toolchain - develop for Android devices (Android SDK version 31.0.0)

remonh87 commented 2 years ago

@farr64 not sure if I understand your question but you can build the latest version against both SDK31 and 30. In the readme we provided instructions how to do this.

farr64 commented 2 years ago

Yes, your instructions are clear.

The question is what default SDK you should choose. Apparently, you chose SDK30. So, the question is why not choose SDK31 as your default.

Thanks, @remonh87

Thidiyas3d commented 2 years ago

I managed to make it work by adding tools:node="remove" to:

 <uses-permission
            android:name="android.permission.BLUETOOTH_SCAN"
            android:usesPermissionFlags="neverForLocation" tools:node="remove" />

don't forgot to add xmlns:tools="http://schemas.android.com/tools" in the top of your manifest. @remonh87 If this is okay I can add it as doc in readme!

But this should be used only with sdk<31? Iā€™m curious to understand why this attribute is automagically set in sdk 30, and by who?

Yes should be used only with sdk<31

Thanks @Taym95