1

我想从我的项目中获取 .apk,但我的成绩有错误。我已删除我的.gradle文件并再次安装它,但我仍然无法获取 .apk。

我有这个:

    android\app\src\main\AndroidManifest.xml:25: Error: AudioService must extend android.app.Service [Instantiatable]
            <service android:name="com.ryanheise.audioservice.AudioService"
                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    H:\podkadeh\android\app\src\main\AndroidManifest.xml:35: Error: MediaButtonReceiver must extend android.content.BroadcastReceiver [Instantiatable]
          <receiver android:name="com.ryanheise.audioservice.MediaButtonReceiver"      
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       
    
       Explanation for issues of type "Instantiatable":
       Activities, services, broadcast receivers etc. registered in the manifest       
       file (or for custom views, in a layout file) must be "instantiatable" by        
       the system, which means that the class must be public, it must have an
       empty public constructor, and if it's an inner class, it must be a static       
       inner class.
    
    2 errors, 0 warnings
    Lint found fatal errors while assembling a release target.
    
    To proceed, either fix the issues identified by lint, or modify your build script as follows:
    ...
    android {
        lintOptions {
            checkReleaseBuilds false
            // Or, if you prefer, you can continue to check for errors in release builds,
            // but continue the build even when errors are found:
            abortOnError false
        }
    }
    ...
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':app:lintVitalRelease'.
    > A failure occurred while executing com.android.build.gradle.internal.lint.AndroidLintTask$AndroidLintLauncherWorkAction
       > There was a failure while executing work items
          > A failure occurred while executing com.android.build.gradle.internal.lint.AndroidLintWorkAction
             > Lint found fatal errors while assembling a release target.
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
    
    * Get more help at https://help.gradle.org
    
    BUILD FAILED in 26s
    Running Gradle task 'assembleRelease'...                           27.1s
    Gradle task assembleRelease failed with exit code 1

在此处输入图像描述

这是我的AndroidManifest.xml 我必须使用音频服务在后台播放音频……</p>

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.podkadeh">
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.WAKE_LOCK"/>
        <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
    
        <application
            android:name="io.flutter.app.FlutterApplication"
            android:label="podkadeh"
            android:icon="@mipmap/ic_launcher">
            <activity
                android:name="com.ryanheise.audioservice.AudioServiceActivity"
                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">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN"/>
                    <category android:name="android.intent.category.LAUNCHER"/>
                </intent-filter>
            </activity>
    
            <service android:name="com.ryanheise.audioservice.AudioService"
                android:exported="true"
                android:required="true"
                >
                <intent-filter>
                    <action android:name="android.media.browse.MediaBrowserService" />
                </intent-filter>
            </service>
        
    
          <receiver android:name="com.ryanheise.audioservice.MediaButtonReceiver"
                android:exported="true"
                android:required="true"
                >
                <intent-filter>
                    <action android:name="android.intent.action.MEDIA_BUTTON" />
                </intent-filter>
            </receiver>
    
            <!-- 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>

这是我的build.gradle

    buildscript {
        ext.kotlin_version =  '1.5.0'
        repositories {
            google()
            jcenter()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:7.0.3'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
    
    allprojects {
        repositories {
            google()
            jcenter()
        }
    }
    
    
    
    
    rootProject.buildDir = '../build'
    subprojects {
        project.buildDir = "${rootProject.buildDir}/${project.name}"
        project.evaluationDependsOn(':app')
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
4

1 回答 1

0

com.ryanheise.audioservice您在项目中包含的库提供的示例程序包含成功编译的配置: https ://github.com/ryanheise/audio_service/blob/minor/audio_service/example/android/app/src/main/AndroidManifest .xml

添加xmlns:tools="http://schemas.android.com/tools"为根节点中的属性<manifest>

tools:ignore="Instantiatable"<activity>节点和 和节点android:exported="true" tools:ignore="Instantiatable"中添加属性。<service><receiver>

于 2022-01-23T21:54:19.037 回答