Android Studio 我的Flutter应用程序的AndroidManifest.xml中存在多个问题

5fjcxozz  于 2022-11-16  发布在  Android
关注(0)|答案(1)|浏览(147)

我想将我的应用发布到Playstore。所以我将app\build.gradle中的minSdkVersion从16更改为31。但是现在,当我构建Appbundle时,我遇到了这个错误。
执行任务“:app:processReleaseMainManifest”失败。
清单合并失败:android:exported需要为元素〈activity#com.example.debt.MainActivity〉显式指定。当相应组件定义了Intent过滤器时,面向Android 12及更高版本的应用需要为android:exported指定显式值。https://developer.android.com/guide/topics/manifest/activity-element#exported有关详细信息,请参阅www.example.com。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.debt">
   <application
        android:label="Money Reminder"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            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>

`

import 'package:flutter/material.dart';
import 'package:debt/colors.dart';
import 'package:debt/add.dart';
import 'package:debt/data.dart';
import 'package:flutter/foundation.dart';

import 'package:hive_flutter/hive_flutter.dart';
late Box box;

List<Data>datalist=[];
Future <void> main() async{
  WidgetsFlutterBinding.ensureInitialized();

  await Hive.initFlutter();

  Hive.registerAdapter(DataAdapter());
  box = await Hive.openBox("infos");
  //wandelt die daten für die Anzeige um
  Map<dynamic, dynamic> data2 = box.toMap();

  //macht aus map liste
  data2.forEach((key, value) {
    if(kDebugMode){
      Data w =Data (key, value);
      datalist.add(w);
    }

  });

runApp(const MaterialApp(
  home: debt(),
  debugShowCheckedModeBanner: false,

));}
// ignore: camel_case_types
class debt extends StatefulWidget {
  const debt({Key? key}) : super(key: key);

  @override
  _debtState createState() => _debtState();
}

// ignore: camel_case_types
class _debtState extends State<debt> {

  Map<String, dynamic> values = {};
  String text = 'Text';
  double w = 100;
  double h = 20;
  Widget quoteTemplate(data){
    return ValueListenableBuilder<Box>(
        valueListenable: Hive.box('infos').listenable(),
        builder: (context, box, widget) {
          return
      Card(
        

      margin: const EdgeInsets.fromLTRB(16, 16, 16, 0),
      child:Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround, // x Achse
          crossAxisAlignment: CrossAxisAlignment.center,    // y Achse
          children: <Widget>[
      Column(
        mainAxisAlignment: MainAxisAlignment.spaceAround, // x Achse
        crossAxisAlignment: CrossAxisAlignment.center,// y Achse

        children: <Widget>[
          Container(alignment: Alignment.center,
            width: 100,
            height: h,
            child: Text(
              data.people,
              style: TextStyle(
                fontSize:  18,
                color: Colors.grey[600],
              )

            ),
          ),
          const SizedBox(height: 6,),
          Container(
            alignment: Alignment.center,

            child: Text(
                data.money,
                style: TextStyle(
                  fontSize:  14,
                  color: Colors.grey[800],
                )

            ),
          ),
        ],
      )
            ,Container(//delete
              alignment: Alignment.center,

              child: TextButton(style: TextButton.styleFrom(

              ),
                onPressed: (){
        box.delete(data.people);
        setState(() {
          Map<dynamic, dynamic> data2 = box.toMap();
          datalist=[];
          data2.forEach((key, value) {
              if(kDebugMode){
                Data w =Data (key, value);
                datalist.add(w);
              }
          });
        });
                },
                child: const Icon(Icons.delete,color: lightblue,),
              ),
            ),
            Container(//minusbutton
              alignment: Alignment.center,

              child: TextButton(style: TextButton.styleFrom(//Minus Butten

              ),
                onPressed: (){
                  var zwischenspeicher = box.get(data.people);

                  double zwischenspeicher2= double.parse(zwischenspeicher) - 1.0;
                  var schulden = zwischenspeicher2.toString();


                  box.put(data.people,schulden);
                  //Updatet das widget
                  setState(() {
                    Map<dynamic, dynamic> data2 = box.toMap();
                    datalist=[];
                    data2.forEach((key, value) {
                      if(kDebugMode){
                        Data w =Data (key, value);
                        datalist.add(w);
                      }
                    });
                  });
                },
                child: const Icon(Icons.remove,color: darkblue,),
              ),
            ),
            Container(//plus Button
              alignment: Alignment.center,

              child: TextButton(style: TextButton.styleFrom(

              ),
                onPressed: (){
                  var zwischenspeicher = box.get(data.people);

                  var zwischenspeicher2= double.parse(zwischenspeicher) + 1;
                  var schulden = zwischenspeicher2.toString();


          box.put(data.people,schulden);

                  setState(() {
                    Map<dynamic, dynamic> data2 = box.toMap();
                    datalist=[];
                    data2.forEach((key, value) {
                      if(kDebugMode){
                        Data w =Data (key, value);
                        datalist.add(w);
                      }
                    });
                  });
                },
                child: const Icon(Icons.add,color: darkbrown,),
              ),
            ),
          ],
      ),
    );});
  }Widget buttond(){
    return
      Padding(
        padding: const EdgeInsets.all(8.0),
        child: Expanded(child: Align(
        alignment: FractionalOffset.bottomRight,
        child:

        FloatingActionButton(
        onPressed: () {
          _awaitReturnValueFromSecondScreen(context);
        },
        child: const Icon(Icons.add),backgroundColor: lightbrown,

    ),),),
      );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        backgroundColor: lightblue ,
        title: const Text("Money Reminder"),
        centerTitle: true,
      ),
      body:

      Padding(
        padding: const EdgeInsets.all(8.0),
        child: ListView(
          children: [
        Column(
          children: datalist.map((data)=> quoteTemplate(data)).toList(),
    ),

          ],
        ),
      ),bottomNavigationBar: Padding(
      padding: const EdgeInsets.fromLTRB(20,0,20,10),
      child:

        ElevatedButton(
          onPressed: () {
            _awaitReturnValueFromSecondScreen(context);
          },
          //child: const Icon(Icons.add,color: Colors.white,),

          child: const Text('add/edit debt',style: TextStyle(fontSize: 18,fontFamily: "Futura",color: Colors.white),),
    style: ElevatedButton.styleFrom( backgroundColor:lightbrown,)

        )

    ),


    );
  }

void _awaitReturnValueFromSecondScreen(BuildContext context) async {

  // start the SecondScreen and wait for it to finish with a result
  final result = await Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => const add(),
      ));

  // after the SecondScreen result comes back update the Text widget with it
  setState(() {
    datalist = result;
  });
  }
}

`

The Problems of the manifest:
https://i.stack.imgur.com/kcZWN.png
https://i.stack.imgur.com/7lkfx.png

I tryed to Invalidate the cashe.
s6fujrry

s6fujrry1#

在你的AndroidManifest.xml文件activity中这样写。

<activity
            android:name=".MainActivity"
            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" 
            android:exported="true"
            tools:node="merge">

相关问题