使用安卓工作室 3.1 开发 AOSP 无法为插桩测试构建测试 apk



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

我的目标:我想按照本 AS 用户指南中的步骤进行插桩测试。


我运行了脚本

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

并在Android Studio中打开了MY_APP.iml。

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

主要的 myAOSP 使用 makefile。

我按照这里的说明进行操作,并使用build.gradle作为模板 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错误,无法为"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/Content/Home

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

我正在寻找一种可行的解决方案,以解决在自定义 AOSP 中为应用程序构建插桩测试 apk 并在 Android Studio 3.1(或更高版本(中对其运行插桩测试的问题。

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

b( 如果无法在上述 a( 中构建 gradle,那么我是否需要使用自定义 AOSP 中的当前生成文件构建插桩化的测试 apk?

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

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

a( 您遇到的 Gradle 错误是什么?哪个 Gradle 任务会给您带来此错误?

b( 您可以设置一个生成文件来构建检测的 APK,例如在此处查看它是如何完成的。您还可以使用贸易联合框架来处理执行和报告生成 - 但您将无法在 AS 中获得集成。

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

最新更新