Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Android Studio 3.1开发AOSP无法为插入指令的测试构建测试apk_Android_Intellij Idea_Android Source_Android Studio 3.0 - Fatal编程技术网

使用Android Studio 3.1开发AOSP无法为插入指令的测试构建测试apk

使用Android Studio 3.1开发AOSP无法为插入指令的测试构建测试apk,android,intellij-idea,android-source,android-studio-3.0,Android,Intellij Idea,Android Source,Android Studio 3.0,我正试图使用Android Studio构建一个定制的AOSP(在Android M上,api 23),因为我想在硬件上运行的定制应用程序上运行检测测试。这是在ubuntu 64上。这对我来说非常令人沮丧,因为没有明确的道路 我的目标:我想遵循仪器化测试的规则 我运行脚本 ~/myAOSP/development/tools/idegen/intellij-gen.sh myApp company/apps/MY_APP 并在Android Studio中打开了MY_APP.iml 现在我正试

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

我的目标:我想遵循仪器化测试的规则


我运行脚本

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

并在Android Studio中打开了MY_APP.iml

现在我正试图使用gradle为我的项目构建apk,同时也测试apk

主myAOSP使用makefiles。

我按照这里的说明操作,并使用build.gradle作为模板

//此buildscript{}块配置驱动生成的代码
构建脚本{
/**
*嵌套存储库{}块声明此生成使用
*jcenter存储库。
*/
存储库{
jcenter()
谷歌()
}
/**
*此块声明对3.1.0版本的依赖关系
*用于构建脚本的Gradle插件。
*/
依赖关系{
classpath'com.android.tools.build:gradle:3.1.2'
}
}
/**
*这一行应用com.android.application插件。请注意,您应该
*仅应用com.android.application插件。将Java插件应用为
*well将导致生成错误。
*/
应用插件:“com.android.application”
/**
*此依赖项块包括项目本身的任何依赖项。这个
*下面一行包括libs目录中的所有JAR文件。
*/
依赖关系{
实现文件树(包括:['*.jar'],目录:“libs”)
测试实现'junit:junit:4.12'
//在此处添加其他库依赖项(请参阅下一步)
androidTestImplementation'com.android.support.test:runner:1.0.2'
}
/**
*android{}块配置android构建的所有参数。
*必须至少为编译目标提供一个值。
*/
安卓{
编译DK23版
buildToolsVersion“27.0.3”
默认配置{
TestInstrumentRunner“android.support.test.runner.AndroidJUnitRunner”
}
/**
*此嵌套sourceSets块将源代码目录指向
*项目中的现有文件夹,而不是使用默认的新文件夹
*组织。
*/
源集{
主要{
manifest.src文件“AndroidManifest.xml”
java.srcDirs=['src']
resources.srcDirs=['src']
aidl.srcDirs=['src']
renderscript.srcDirs=['src']
res.srcDirs=['res']
assets.srcDirs=['assets']
}
//将测试移动到tests/java、tests/res等。。。
androidTest.setRoot('tests'))
/**
*将生成类型移动到生成类型/
*例如,build-types/debug/java、build-types/debug/AndroidManifest.xml。。。
*这会将它们移出src/…下的默认位置,这将
*与主源集正在使用的src/冲突。
*应同时添加新的构建类型或产品风格
*通过类似的定制。
*/
setRoot('build-types/debug')
setRoot('build-types/release')
}
}
存储库{
jcenter()
谷歌()
}
还有一个gradle错误:由于Android M是用JDK 1.7构建的,但Android Studio gradle使用的是1.8,因此我遵循了这些步骤,但出现了gradle错误,无法为“type org.gradle.api.project”的根项目“MY_project”设置未知属性“sourceCompatibility”。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-`

我看到过类似这样的帖子,但它们已经过时或不相关。 也和

我正在寻找一个有效的解决方案,在Android Studio 3.1(或更高版本)中为定制AOSP中的应用程序构建一个插入式测试apk,并在其上运行插入式测试

a) 如果可以按照3.1(或更高版本)在gradle中构建仪表化测试apk,那么请建议对显示的gradle错误进行修复

b) 如果上面a)中的gradle构建不可能,那么我是否需要使用定制AOSP中的当前makefile构建插入指令的测试apk


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

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

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

b) 您可以设置一个Makefile来构建插入指令的APK,例如,查看它是如何完成的。您还可以使用来处理执行和报告生成,但在AS中无法实现集成


c) 通过检测UI,您是指使用“播放按钮”启动测试,还是在测试运行时实时显示测试结果?如果您的意思是显示实时结果,那么我认为这是不可能的-据我所知,这取决于connectedAndroidTest任务。如果您只想执行测试,您可以创建一个自定义的Gradle任务,该任务只运行“adb shell am instrument…”命令。

在中,您需要像往常一样添加JDK(指向现有的JDK),并在创建后删除“Classpath”下的所有jar条目tab@y.bed
// 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()
}