我的android项目只有aidl文件,项目结构如下:
MyProject/
src/
main/
com.my.aidl/
IMyService.aidl
pom.xml
Run Code Online (Sandbox Code Playgroud)
我用maven构建我的android项目.我的pom使用dexguard-maven-plugin,它是android-maven-plugin的扩展.
在插件配置中,我明确指定了source aidl文件的目录和生成的java文件的目录.
<build>
<plugins>
<plugin>
<groupId>com.saikoa.dexguard.maven</groupId>
<artifactId>dexguard-maven-plugin</artifactId>
<configuration>
<aidlSourceDirectory>
${project.basedir}/src/main/com/my/aidl
</aidlSourceDirectory>
<genDirectoryAidl>
${project.build.directory}/generated-sources/aidl/main/com/my/aidl
</genDirectoryAidl>
</configuration>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
但在我运行后,mvn clean install -e
我得到以下错误跟踪:
[ERROR] Failed to execute goal com.saikoa.dexguard.maven:dexguard-maven-plugin:6.1.18:generate-sources (default-generate-sources) on project MyProject: Execution default-generate-sources of goal com.saikoa.dexguard.maven:dexguard-maven-plugin:6.1.18:generate-sources failed. NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.saikoa.dexguard.maven:dexguard-maven-plugin:6.1.18:generate-sources (default-generate-sources) on project MyProject: Execution default-generate-sources of goal com.saikoa.dexguard.maven:dexguard-maven-plugin:6.1.18:generate-sources failed.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:224)
at …
Run Code Online (Sandbox Code Playgroud) 我正在使用 Kotlin 和 Dagger 2 开发一个 Android 项目。我有一个NetworkModule
它应该提供一个 Retrofit 的单例实例。我在其中定义了所有这些提供程序功能。
下面的所有代码片段都在里面NetworkModule
:
@Module
object NetworkModule {
...
}
Run Code Online (Sandbox Code Playgroud)
我想提供HttpRequestInterceptor
,这是我尝试过的:
@Provides
@JvmStatic
internal fun provideHttpRequestInterceptor(): Interceptor {
// compiler error: Cannot inline bytecode built with JVM target 1.8 into
// bytecode that is being built with JVM target 1.6,
// please specify proper '-jvm-target' option
return Interceptor { chain ->
val original = chain.request()
val requestBuilder = original.newBuilder()
val request = requestBuilder.build()
chain.proceed(request)
}
}
Run Code Online (Sandbox Code Playgroud)
但是上面的代码总是给我这个编译器错误: …
我在线阅读了Google移动广告SDK文档.在那里,它提供了如何使用AdMob,Ad Exchange和DFP广告管理系统(DFP)的指导.
但是,在阅读了这些指导之后,我真的对它们之间的差异感到困惑.我觉得他们的移动Android应用程序几乎相同.有人可以让我清楚这三者中最主要的差异吗?
我正在使用Mockito来编写我的测试用例.我有一个简单的类,其中包含一个countPerson(boolean)
我有兴趣测试的函数:
public class School {
//School is a singleton class.
public void countPerson(boolean includeTeacher) {
if (includeTeacher) {
countIncludeTeacher();
return;
}
countOnlyStudents();
}
public void countIncludeTeacher() {...}
public void countOnlyStudents() {...}
}
Run Code Online (Sandbox Code Playgroud)
在我的单元测试中,我想测试countPerson(boolean)
方法:
@Test
public void testCountPerson() {
School mSchool = School.getInstance();
School spySchool = Mockito.spy(mSchool);
spySchool.countPerson(true);
//Verify the function countIncludeTeacher is invoked once
verify(spySchool).countIncludeTeacher();
//Until here things are working well.
spySchool.countPerson(false);
//ERROR HERE when I try to verify the function has 0 times …
Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的类Handler
,当它处理消息时它再次发送新消息:
public class MyRepeatTask{
…
public void startTask() {
// send message with delay 5 sec
handler.sendMessageDelayed(handler.obtainMessage(…), 5000);
}
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
// I put a log for unit test
System.out.println(“handling message …”);
// send message with delay again
handler.sendMessageDelayed(handler.obtainMessage(…), 5000);
}
}
}
Run Code Online (Sandbox Code Playgroud)
如上所示,当startTask()
调用时,处理程序在5秒内开始发送消息.然后,在handleMessage()
回调中,handler
再次发送延迟5秒的消息.这样做的目的是反复做一些任务(比如System.out.println()
).
我用Robolectric测试上面的类:
@RunWith(RobolectricTestRunner.class)
public class MyRepeatTaskTest {
@Test
public void testStartTask() {
MyRepeatTask task = …
Run Code Online (Sandbox Code Playgroud) 我注意到在android开发者网页上,有一个标题为" Action bar兼容性 "的THIS文档.
它是否显示旧的 Android API 小于 v11 的操作栏实现,还是显示如何使用API v11及更高版本实现操作栏?我对此页面感到困惑.
android android-widget android-emulator android-intent android-layout
我在一个名为的分支上feature-1
.我跑了git log
,这给我看了一堆提交:
commit <HASH-1>
…
commit <HASH-2>
…
commit <HASH-3>
…
commit <HASH-4>
…
Run Code Online (Sandbox Code Playgroud)
现在我想commit <Hash-3>
和旧的承诺是在feature-1
分支,而commit <HASH-2>
和新的承诺是在一个名为新的分支功能-2 .我怎样才能做到这一点?
在swift中,我有一个School
类,它有一个students
类型的属性[AnyObject]!
class School : NSObject {
var students: [AnyObject]!
...
}
Run Code Online (Sandbox Code Playgroud)
我有一个实例School
和一个NSArray
代表学生姓名的字符串.我想将此NSArray
变量分配给students
:
var school = School()
var studentArray : NSArray = getAllStudents()
//ERROR:Cannot assign a value of type 'NSArray' to a value of type '[AnyObject]'
school.students = studentArray
Run Code Online (Sandbox Code Playgroud)
为什么这个错误?是不是swift中的数组与目标c中的NSArray兼容?如何摆脱上面的编译器错误?
我已经阅读了苹果的Swift编程语言(swift2)的可选链接章节.在本章中,没有关于可选的问号提后的函数名称,但左括号前.
但我看到下面的SWIFT代码这个苹果公司的文件(以下简称"代表团"部分):
//There is a question mark right after 'window'
if let fullScreenSize = myDelegate?.window?(myWindow, willUseFullScreenContentSize: mySize) {
print(NSStringFromSize(fullScreenSize))
}
Run Code Online (Sandbox Code Playgroud)
在函数名之后但在左括号之前有问号是什么意思?
我在我的node.js 项目中使用TypeOrm。我知道从数据库中查找记录我可以这样做:
userRepository.find({ where: { firstName: "John" } });
Run Code Online (Sandbox Code Playgroud)
它执行查询:
SELECT * FROM "user"
WHERE "firstName" = 'John'
Run Code Online (Sandbox Code Playgroud)
但现在,仅当存在该值时,我才需要在“where”条件中添加另一个归档检查。例如,我还想检查company
SQL“where”条件,但前提是company
存在值。
我尝试了以下操作,我想知道我可以通过给出默认的空字符串(''
如果company
不存在)然后将其传递给find
函数来执行以下操作where
吗?
const company = params.company ? params.company : '';
userRepository.find({ where: { firstName: "John", company: company } });
Run Code Online (Sandbox Code Playgroud)
但它仍然会添加"company"=''
到最终的 SQL 查询中,这是不好的。我想知道 TypeORM 中是否有一个现有函数可以动态决定仅在where
存在值而不是空字符串时添加更多条件?