Android Studio中的依赖项问题 [英] Issues with dependencies in Android Studio

查看:111
本文介绍了Android Studio中的依赖项问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用Android开发非常陌生,并且正在尝试为Android应用开发自动化测试.在运行测试时,我总是遇到无法解决依赖性问题的信息.我所附的代码只是尝试单击该应用程序的登录按钮.这是我的代码:

主应用程序:

  package com.example.test;导入io.appium.java_client.android.AndroidDriver;导入org.junit.Before;导入org.junit.Test;导入org.openqa.selenium.By;导入org.openqa.selenium.remote.DesiredCapabilities;导入java.net.MalformedURLException;导入java.net.URL;/***仪器化测试,将在Android设备上执行.** @见< ahref ="http://d.android.com/tools/testing"> Testingdocumentation</a>*///@RunWith(AndroidJUnit4.class)公共类ExampleInstrumentedTest {私人AndroidDriver驱动程序;@前公共无效setup()抛出MalformedURLException {DesiredCapabilities功能=新的DesiredCapabilities();abilities.setCapability("deviceName","emulator-5444");abilities.setCapability("platFormName","Android");abilities.setCapability("appPackage","com.mol.molwallet.uat");capability.setCapability("appActivity","com.mol.molwallet.start.SplashActivity");abilities.setCapability("noReset","true");驱动程序=新的AndroidDriver(新的URL("http://127.0.0.1:4725/wd/hub"),功能);}@测试公共无效myFirstTest(){//正在测试的应用程序的上下文.driver.findElement(By.xpath("//* [@ text ='LOG IN']")).click();//assertEquals("com.example.test,appContext.getPackageName());}} 

App/Build.Gridle:

  apply插件:"com.android.application"安卓 {compileSdkVersion 29buildToolsVersion"29.0.1"defaultConfig {applicationId"com.example.test"minSdkVersion 15targetSdkVersion 29版本代码1versionName"1.0"testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"}buildTypes {释放 {minifyEnabled falseproguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),'proguard-rules.pro'}}}依赖项{实现fileTree(dir:'libs',包括:['* .jar'])//noinspection GradleCompatible实施'com.android.support:appcompat-v7:+'实现'com.android.support.constraint:constraint-layout:1.1.3'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'androidTestImplementation'com.android.support:support-annotations:24.0.0'实现("com.android.support:support-v4:27.1.1")//实施项目(':react-native-fast-image')}if(hasProperty('buildScan')){buildScan {termsOfServiceUrl ='https://gradle.com/terms-of-service';termsOfServiceAgree ='是'}} 

Project/Build.gradle

 //顶级构建文件,您可以在其中添加所有子项目/模块共有的配置选项.buildscript {储存库{谷歌()jcenter()}依赖项{classpath'com.android.tools.build:gradle:3.1.0'//注意:请勿在此处放置应用程序依赖项;他们属于//在各个模块的build.gradle文件中}}所有项目{储存库{谷歌()jcenter()}}任务清理(类型:删除){删除rootProject.buildDir} 

运行时,出现以下错误

 "build.gradle:无法解决':app @ releaseUnitTest/compileClasspath'的依赖关系:找不到与com.android.support:appcompat-v7:29.+匹配的任何版本.< a href =无法解决&#39;:app @ releaseUnitTest/compileClasspath&#39;的依赖关系:找不到与com.android.support:appcompat-v7:29.+匹配的任何版本.">显示详细信息</a>受影响的模块:< a href ="openFile:C:/Users/chiomeng.lam/IntelliJIDEAProjects/Test/app/build.gradle"> app</a> 

基于错误,我有些印象是某些版本是错误的.但是我的问题是,什么版本的不匹配.

解决方案

您正在使用 compileSdk 29 ,对于sdk 29,没有支持库版本,因为它已移至AndroidX库./p>

在Android Studio中转到菜单栏,选择重构,然后迁移到AndroidX ,即可解决此问题.

如果需要临时解决方案,可以将compileSdk更改为27,但是,如果尚未发布应用程序,则必须先更改为Sdk 29,才能在PlayStore上发布它.根据要求:

从2019年8月1日开始,Google Play要求新应用至少以Android 9.0(API级别28)为目标,并且应用更新自2019年11月1日开始以Android 9.0为目标.在这些日期之前,新应用和应用更新必须以至少是Android 8.0(API级别26).

注意:随着Android 9.0(API级别28)的发布,Jetpack包含了一个新版本的支持库AndroidX.AndroidX库包含现有的支持库,还包含最新的Jetpack组件.您可以继续使用支持库.历史工件(那些版本为27和更低版本,并打包为android.support.*的工件)将在Google Maven上可用.但是,所有新的库开发都将在AndroidX库中进行.我们建议在所有新项目中使用AndroidX库.您还应该考虑将现有项目也迁移到AndroidX.

如果在重构期间弹出任何问题,请查看此重构页面,并使用此列表中给出的新软件包替换您已经在使用的所有软件包:

https://developer.android.com/jetpack/androidx/migrate#artifact_mappings

I am very new to developing in Android and I am trying to develop test automation for Android apps. When I run my test, I keep hitting the unable to resolve dependency issues. My attached code is an attempt to just click on the login button of the app. Here is my code :

Main app:

package com.example.test;
import io.appium.java_client.android.AndroidDriver;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a 
href="http://d.android.com/tools/testing">Testingdocumentation</a>
 */
//@RunWith(AndroidJUnit4.class)

public class ExampleInstrumentedTest {
    private AndroidDriver driver;
    @Before
    public void setup() throws MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "emulator-5444");
        capabilities.setCapability("platFormName","Android");           
        capabilities.setCapability("appPackage",
        "com.mol.molwallet.uat");

        capabilities.setCapability
        ("appActivity","com.mol.molwallet.start.SplashActivity");
        capabilities.setCapability("noReset","true");

        driver = new AndroidDriver(new URL 
        ("http://127.0.0.1:4725/wd/hub"),capabilities);
   }
   @Test
   public void myFirstTest() {
       //Context of the app under test.
       driver.findElement(By.xpath("//*[@text='LOG IN']")).click();
       //assertEquals("com.example.test", appContext.getPackageName());
   }
}

App/Build.Gridle:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 29
    buildToolsVersion "29.0.1"
    defaultConfig {
        applicationId "com.example.test"
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:+'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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'
    androidTestImplementation 'com.android.support:support-annotations:24.0.0'
    implementation("com.android.support:support-v4:27.1.1")
    //implementation project(':react-native-fast-image')

}
if(hasProperty('buildScan')){
    buildScan {
        termsOfServiceUrl = 'https://gradle.com/terms-of-service';
        termsOfServiceAgree = 'yes'
    }
}

Project/Build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Upon running, I get the following errors

"build.gradle: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not find any version that matches com.android.support:appcompat-v7:29.+.
<a href="Unable to resolve dependency for &#39;:app@releaseUnitTest/compileClasspath&#39;: Could not find any version that matches com.android.support:appcompat-v7:29.+.">Show Details</a>
Affected Modules: <a href="openFile:C:/Users/chiomeng.lam/IntelliJIDEAProjects/Test/app/build.gradle">app</a>"

Base on the error, I kind of get the impression that some version is mismathc. But my problem is, what version of what is mismatched.

解决方案

You are using compileSdk 29 , for sdk 29 there is no version of support libraries since it has been moved to AndroidX libraries.

Goto Menu bar in Android Studio, Select Refactor then Migrate to AndroidX, that should solve the issue.

If you need a temporary solution, you can change compileSdk to 27, however you won't be able to publish it on PlayStore until you change to Sdk 29 if your app hasn't already been published. As per requirements:

Starting August 1, 2019, Google Play requires that new apps target at least Android 9.0 (API level 28), and that app updates target Android 9.0 from November 1, 2019. Until these dates, new apps and app updates must target at least Android 8.0 (API level 26).

Note: With the release of Android 9.0 (API level 28) there is a new version of the support library called AndroidX which is part of Jetpack. The AndroidX library contains the existing support library and also includes the latest Jetpack components. You can continue to use the support library. Historical artifacts (those versioned 27 and earlier, and packaged as android.support.*) will remain available on Google Maven. However, all new library development will occur in the AndroidX library. We recommend using the AndroidX libraries in all new projects. You should also consider migrating existing projects to AndroidX as well.

If any issues pop up during refactoring, take a look at this refactoring page and replace the any packages you are already using with new ones as given in this list:

https://developer.android.com/jetpack/androidx/migrate#artifact_mappings

这篇关于Android Studio中的依赖项问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆