颤振:无法解析 com.android.support:support-v4:27.1.0

Posted

技术标签:

【中文标题】颤振:无法解析 com.android.support:support-v4:27.1.0【英文标题】:Flutter: Could not resolve com.android.support:support-v4:27.1.0 【发布时间】:2020-01-09 18:04:53 【问题描述】:

我尝试将flute_music_player: ^0.0.6 添加到我的flutter 项目依赖项中

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.2
  flute_music_player: ^0.0.6

并在项目运行后得到以下错误。

无法解析 com.android.support:support-v4:27.1.0。 > 不能 获取资源 'https://dl.google.com/dl/android/maven2/com/android/support/support-v4/27.1.0/support-v4-27.1.0.pom'。

无法 HEAD 'https://dl.google.com/dl/android/maven2/com/android/support/support-v4/27.1.0/support-v4-27.1.0.pom'。 sun.security.validator.ValidatorException:PKIX 路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException: 无法找到请求目标的有效认证路径

build.gradle (path => project_dir/android/build.gradle)

buildscript 
    repositories 
        google()
        jcenter()
    

    dependencies 
        classpath 'com.android.tools.build:gradle:3.0.1'
    


allprojects 
    repositories 
        mavenLocal()
        jcenter()
        maven 
            url 'https://maven.google.com'
        
    


rootProject.buildDir = '../build'
subprojects 
    project.buildDir = "$rootProject.buildDir/$project.name"

subprojects 
    project.evaluationDependsOn(':app')


task clean(type: Delete) 
    delete rootProject.buildDir

android 应用 build.gradlepath => project_dir/android/app/build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) 
    localPropertiesFile.withReader('UTF-8')  reader ->
        localProperties.load(reader)
    


def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) 
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")


def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) 
    flutterVersionCode = '1'


def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) 
    flutterVersionName = '1.0'


apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android 
    compileSdkVersion 26

    lintOptions 
        disable 'InvalidPackage'
    

    defaultConfig 
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.child_controller"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    

    buildTypes 
        release 
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        
    


flutter 
    source '../..'


dependencies 
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

以下是我的依赖小部件源代码

import "package:flute_music_player/flute_music_player.dart";
import "package:flutter/material.dart";

class MyMusicList extends StatefulWidget 
  @override
  _MyMusicListState createState() => _MyMusicListState();


class _MyMusicListState extends State<MyMusicList> 

  List<dynamic> _songs;

  @override
  void initState() 
    super.initState();
    initMusicPlayer();
  

  void initMusicPlayer() async 
    var songs = await MusicFinder.allSongs();
    songs = List.from(songs);

    setState(() 
      _songs = songs;
    );
  

  @override
  Widget build(BuildContext context) 
    return Scaffold(
      appBar: AppBar(
        title: const Text("Tap the Song to Play"),
      ),
      body: Container(
        child: ListView.builder(
          itemCount: (_songs != null) ? _songs.length: 0,
          itemBuilder: (context, int index) 
            return ListTile(
              leading: CircleAvatar(
                child: Text(_songs[index].title[0]),
              ),
              title: Text(_songs[index].title),
            );
          ,
        ),
      ),
    );
  

我很确定我的 Android Studio IDE 版本已更新,并且所有支持存储库、依赖项和 API 都已安装。

【问题讨论】:

【参考方案1】:

我尝试并按照以下步骤在 Windows 10 中解决此问题。

防火墙权限

允许应用通过 Windows Defender 防火墙进行通信。

将 Android Studio 执行程序 studio.exestudio64.exe 添加到防火墙 (内C:\Program Files\Android\Android Studio\bin

在本地计算机上具有高级安全性的 Windows Defender 防火墙

在入站和出站规则下允许被阻止的网络连接Java(TM) Platform SE 二进制

Android Studio IDE 活动

在终端执行命令 flutter run --release 进行签名 使用调试密钥进行开发。

flutter clean

flutter pub get

File - Save All 

File - Sync with File System 

File - Invalidate Caches / Restart - Invalidate and Restart

// and again after IDE Restart

File - Sync with File System

最后,我的应用程序成功执行。

【讨论】:

以上是关于颤振:无法解析 com.android.support:support-v4:27.1.0的主要内容,如果未能解决你的问题,请参考以下文章

颤振:无法解析 com.android.support:support-v4:27.1.0

颤振构建错误无法解析 com.google.android.gms:play-services-location:16.+

无法解析 URL“https://pub.dartlang.org”。错误 (69):无法“发布升级”颤振工具。 5 秒后重试...(还剩 9 次尝试)

颤振错误:无法解析 com.google.android.gms:play-services-location:16.+,状态码 502 [重复]

未加载颤振图像(例外:解析图像编解码器)

无法解析配置“:app:debugRuntimeClasspath”的所有文件。,颤动