我试图使用Android构建一个定制的AOSP (在Android,api 23上),因为我想在运行在硬件上的定制应用程序上运行仪器测试。这是在ubuntu 64上。这对我来说是非常令人沮丧的,因为没有明确的道路。
我的目标:,我想跟随此步骤作为用户指南。进行仪器化测试。
我运行了剧本
~/myAOSP/development/tools/idegen/intellij-gen.sh myApp公司/APP/MY_APP
并在Android中打开了MY_APP.iml。
现在,我正在尝试为我的项目和测试apk使用gradle构建apk。
主myAOSP使用makefiles.
我遵循这里的说明,并使用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是用JDK1.7构建的,但是Android使用了1.8,所以我遵循了这些步骤,但是有gradle错误,无法为'sourceCompatibility‘类型的根项目'MY_PROJECT’设置未知属性‘org.gradle.api.Project’。$HOME/..gradle/gradle.properties中的docs.gradle.org/current/userguide/building_java_projects.html # javaHome=/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home
targetJavaVersion=1.7 build.gradle sourceCompatibility = targetJavaVersion -`
我看到了像用Android开发AOSP这样的帖子,但它们已经过时了,或者不相关。还有http://ronubo.blogspot.com/2016/01/debugging-aosp-platform-code-with.html?view=magazine和错误:(23,17)未能解决: junit:junit:4.12
我正在寻找一个可行的解决方案来解决在定制的AOSP中为应用程序构建一个仪器化测试apk的问题,并在AndroidStudio3.1(或更高版本)上运行仪器化测试。
( a)如果可以在gradle中将仪器化测试apk构建为3.1 (或更高版本),那么请建议对显示的gradle错误进行修正。
( b)如果上面的gradle构建是不可能的,那么我是否需要使用自定义的AOSP中的当前makefile构建仪器化的测试apk?
c)如果我使用makefile构建了仪器化的测试apk,那么我是否还可以使用工具UI在硬件上运行测试呢?
发布于 2018-06-20 22:33:20
是的,用AOSP中的Gradle构建APK和测试应用APK是可能的,但困难取决于它们的依赖关系,即Makefile可能指的是预先构建的二进制文件或AOSP中的其他模块,在公共Maven repos中可能没有等效的依赖项,因此您需要通过其他方法来提取这些依赖项。如果您的应用程序是系统应用程序,则需要为签名步骤提供平台签名。
( a)你所得到的分度误差是多少?哪个分级任务给了你这个错误?
( b)您可以设置一个Makefile来构建工具化的APK,例如,查看它是如何完成这里的。您还可以使用贸易联合会框架来处理执行和报告生成--但是您不会在AS中获得集成。
( c)通过工具UI,您是指使用"play按钮“启动测试,还是在测试运行时显示测试结果?如果您的意思是显示实时结果,那么我认为这是不可能的--据我所知,这取决于connectedAndroidTest任务。如果您只想执行测试,您可以创建一个定制的Gradle任务,该任务只运行“亚行外壳设备.”命令。
https://stackoverflow.com/questions/50415724
复制相似问题