使用Android Studio 3.1开发AOSP无法为仪表化测试构建测试apk [英] Developing AOSP with Android Studio 3.1 Cannot build test apk for instrumented tests

查看:322
本文介绍了使用Android Studio 3.1开发AOSP无法为仪表化测试构建测试apk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Android Studio构建定制的AOSP(在Android M,api 23上),因为我想对在硬件上运行的自定义应用程序运行检测测试。这是在ubuntu 64上。对我来说非常令人沮丧,因为没有明确的切入路径。

I am trying to build a customized AOSP (on Android M, api 23) using Android Studio because I want to run instrumented tests on custom apps running on the hardware. This is on ubuntu 64. It is very frustrating for me as there is no clear cut path.

我的目标:我想关注此AS用户指南中的步骤,用于检测测试。

My goal: I want to follow the steps in this AS user guide for instrumented tests.

我运行了脚本

〜/ myAOSP / development /tools/idegen/intellij-gen.sh myApp公司/ apps / MY_APP

~/myAOSP/development/tools/idegen/intellij-gen.sh myApp company/apps/MY_APP

并在Android Studio中打开MY_APP.iml。

and opened MY_APP.iml in Android Studio.

现在我正在尝试使用gradle为我的项目构建apk,以及测试apk。

Now I am trying to build the apk using gradle just for my project, and also the test apk.

主myAOSP使用makefile。

我按照此处的说明操作并使用build.gradle作为模板 https://developer.android.com/studio/intro/migrate#migrate-intellij

I followed the instructions here and also used the build.gradle as a template https://developer.android.com/studio/intro/migrate#migrate-intellij

// This buildscript{} block configures the code driving the build
buildscript {
   /**
    * The nested repositories{} block declares that this build uses the
    * jcenter repository.
    */
    repositories {
        jcenter()
        google()
    }

   /**
    * This block declares a dependency on the 3.1.0 version
    * of the Gradle plugin for the buildscript.
    */
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
    }
}

/**
 * This line applies the com.android.application plugin. Note that you should
 * only apply the com.android.application plugin. Applying the Java plugin as
 * well will result in a build error.
 */
apply plugin: 'com.android.application'

/**
 * This dependencies block includes any dependencies for the project itself. The
 * following line includes all the JAR files in the libs directory.
 */
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    testImplementation 'junit:junit:4.12'
    // Add other library dependencies here (see the next step)
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
}

/**
 * The android{} block configures all of the parameters for the Android build.
 * You must provide a value for at least the compilation target.
 */
android {
    compileSdkVersion 23
    buildToolsVersion '27.0.3'
    defaultConfig {
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    /**
    * This nested sourceSets block points the source code directories to the
    * existing folders in the project, instead of using the default new
    * organization.
    */
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        androidTest.setRoot('tests')

       /**
        * Move the build types to build-types/<type>
        * For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        * This moves them out of them default location under src/<type>/... which would
        * conflict with src/ being used by the main source set.
        * Adding new build types or product flavors should be accompanied
        * by a similar customization.
        */
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
     }
}

repositories {
    jcenter()
    google()
}

还有一个gradle错误:由于Android M是使用JDK 1.7构建的,但Android Studio gradle使用1.8,我遵循了步骤但是有gradle错误,无法为root项目设置未知属性'sourceCompatibility'类型为org.gradle.api.Project的MY_PROJECT'。 docs.gradle.org/current/userguide/building_java_projects.html#in $ HOME / .gradle / gradle.properties
javaHome = / Library / Java / JavaVirtualMachines / 1.7.0.jdk / Contents / Home

There was also a gradle error: Since Android M is being built with JDK 1.7 but Android Studio gradle uses 1.8, I followed the steps but had gradle error, Could not set unknown property 'sourceCompatibility' for root project 'MY_PROJECT' of `type org.gradle.api.Project. docs.gradle.org/current/userguide/building_java_projects.html # in $HOME/.gradle/gradle.properties javaHome=/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home

targetJavaVersion = 1.7 build.gradle sourceCompatibility = targetJavaVersion -`

targetJavaVersion=1.7 build.gradle sourceCompatibility = targetJavaVersion –`

我看过像使用Android Studio开发AOSP 但它们已过期或不相关。
另外 http:// ronubo.blogspot.com/2016/01/debugging-aosp-platform-code-with.html?view=magazine 错误:(23,17)无法解决:junit:junit:4.12

I saw posts like Developing AOSP with Android Studio but they are out of date or not relevant. Also http://ronubo.blogspot.com/2016/01/debugging-aosp-platform-code-with.html?view=magazine and Error:(23, 17) Failed to resolve: junit:junit:4.12

我正在寻找在Android Studio 3.1(或更高版本)中,针对自定义AOSP中的应用程序构建检测测试apk并在其上运行检测测试的问题的工作解决方案。

I am looking for a working solution to the problem of building an instrumented test apk for an app in customized AOSP, and running instrumented tests on it, in Android Studio 3.1 (or later).

a)如果可以在gradle AS 3.1(或更高版本)中构建检测测试apk,那么请建议修复显示的gradle错误。

a) if it is possible to build the instrumented test apk in gradle AS 3.1 (or later), then please suggest a fix to the gradle error shown.

b)如果上面的a)中的gradle构建是不可能的,那么我是否需要使用自定义AOSP中的当前makefile构建检测测试apk?

b) if gradle build in a) above is NOT possible, then do I need to build instrumented test apk using the current makefiles in the customized AOSP?

c)如果我使用makefiles构建检测测试apk,那么我是否仍然可以使用AS中的检测UI在硬件上运行测试?

c) if I build the instrumented test apk using makefiles, then can I still use the instrumentation UI in AS to run the tests on the hardware?

推荐答案

是的,可以在AOSP中使用Gradle构建应用APK和测试应用APK,但难度取决于它们的依赖关系,即Makefile可能是指AOSP中预先构建的二进制文件或其他模块,公共Maven存储库中可能没有等效的依赖项,因此您需要通过其他方式引入这些依赖项。如果您的应用是系统应用,则需要为签名步骤提供平台签名。

Yes, it's possible to build an app APK and a test app APK with Gradle in AOSP, but the difficulty depends on their dependencies, i.e. where the Makefile may refer to a pre-built binary or another module in AOSP, there may not be an equivalent dependency in the public Maven repos so you'll need to pull in those dependencies by other means. And if your app is a system app, you'll need to provide the platform signature for the signing step.

a)您获得的Gradle错误是什么?哪个Gradle任务会给你这个错误?

a) What is the Gradle error you're getting? And which Gradle task gives you that error?

b)您可以设置一个Makefile来构建已检测的APK,例如看看它是如何完成的这里。您还可以使用贸易联盟框架来处理执行和报告生成 - 但是你不会在AS中进行集成。

b) You can set up a Makefile to just build the instrumented APK, for example see how it's done here. You can also use the Trade Federation framework to handle the execution and report generation - but you won't get the integration in AS.

c)通过检测UI,你的意思是用播放按钮开始测试,或显示测试运行时测试结果是否正常?如果你的意思是显示实时结果,那么我不相信这是可能的 - 据我所知它取决于connectedAndroidTest任务。如果您只想执行测试,可以创建一个自定义Gradle任务,该任务只运行adb shell am instrument ...命令。

c) By instrumentation UI, do you mean starting the tests with the "play button", or showing the test results live as the tests are running? If you mean showing the live results, then I don't believe that's possible - as far as I know it depends on the connectedAndroidTest task. If you just want to execute tests you can create a custom Gradle task that just runs the "adb shell am instrument ..." command.

这篇关于使用Android Studio 3.1开发AOSP无法为仪表化测试构建测试apk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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