我想基于当前的buildType在Android Gradle项目中动态添加依赖项.我知道我可以在依赖项中指定buildType:
compile project(path: ':lib1', configuration: 'debug')
Run Code Online (Sandbox Code Playgroud)
但是,如何使用当前的buildType来指定要导入的库的哪个变体,以便调试版本或发布版本自动导入库的调试版本或发行版本?我想要的是这样的(其中currentBuildType是一个包含当前使用的buildType名称的变量):
compile project(path: ':lib1', configuration: currentBuildType)
Run Code Online (Sandbox Code Playgroud)
我要导入的库项目已设置publishNonDefault true
,因此将发布所有buildType.
我想用Java生成一个RSA-SHA256签名,但我不能让它在控制台上生成与OpenSSL相同的签名.
这就是我对OpenSSL所做的事情(遵循本教程):
生成密钥对:
openssl genrsa -out private.pem 1024
Run Code Online (Sandbox Code Playgroud)
提取公钥:
openssl rsa -in private.pem -out public.pem -outform PEM -pubout
Run Code Online (Sandbox Code Playgroud)
创建数据哈希:
echo 'data to sign' > data.txt
openssl dgst -sha256 < data.txt > hash
Run Code Online (Sandbox Code Playgroud)
生成的哈希文件以(stdin)=
我手工删除的内容开头(首先忘了提及它,谢谢马塔).
签名哈希:
openssl rsautl -sign -inkey private.pem -keyform PEM -in hash > signature
Run Code Online (Sandbox Code Playgroud)
要在Java中重现结果,我首先将私钥从PEM转换为DER:
openssl pkcs8 -topk8 -inform PEM -outform DER -in private.pem -nocrypt > private.der
Run Code Online (Sandbox Code Playgroud)
现在我编写了这个Java类来生成相同的签名:
public class RSATest {
public static void main(String[] args) throws IOException,
NoSuchAlgorithmException, InvalidKeySpecException,
InvalidKeyException, SignatureException {
byte[] …
Run Code Online (Sandbox Code Playgroud) 从Android API Level 15开始,有一种方法 public Drawable getDrawableForDensity (int id, int density)
可以检索特定屏幕密度的可绘制对象.在API级别15之前有没有办法做到这一点?
PackageManager.DONT_KILL_APP的API文档说:
设置此项时要小心,因为更改组件状态会使包含应用程序的行为无法预测.
不幸的是,他们没有详细说明不可预测的行为意味着什么.
在我的应用程序中,我正在切换活动的启用状态.首先,服务启用活动并启动它:
getPackageManager().setComponentEnabledSetting(
new ComponentName(MyService.this.getApplicationContext(),
MyActivity.class),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
final Intent launchIntent = new Intent(context, MyActivity.class);
launchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(launchIntent);
Run Code Online (Sandbox Code Playgroud)
如果(单顶)活动再次开始或被破坏,它会将自己设置为再次禁用:
@Override
protected void onDestroy() {
log.d("ON DESTROY");
super.onDestroy();
getPackageManager().setComponentEnabledSetting(getComponentName(),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
}
@Override
protected void onNewIntent(Intent intent) {
if (someCondition) {
getPackageManager().setComponentEnabledSetting(getComponentName(),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP);
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_HOME);
startActivity(i);
finish();
return;
}
super.onNewIntent(intent);
}
Run Code Online (Sandbox Code Playgroud)
通常情况下一切正常,但有时对象是空的,在onResume()
其中创建onCreate()
并且不触及任何其他地方.我无法在调试器中重建这个问题,但我得到了许多带有NullPointerExceptions的错误报告,onResume()
如果onCreate()
之前真的被调用过,那是不可能的.
一个简单的例子是:
private String s;
@Override
public void onCreate(Bundle savedInstanceState) …
Run Code Online (Sandbox Code Playgroud) android nullpointerexception onresume android-package-managers
我有一个简单的代码生成器G,它从我的项目中读取接口A并从中生成一个新的接口B. 因此我需要实现这个目标:
步骤1和3由maven-compiler-plugin处理,而对于步骤2,我使用maven-exec-plugin.目前步骤1和2运行良好,但我无法弄清楚如何再次运行编译器插件来编译新生成的B版本.
这可能与maven有关,还是有另一种方法可以解决我的问题?
解:
基于khmarbaise的答案,我将此添加到我的pom.xml中,让第一次编译在generate-sources阶段运行,代码生成在process-sources阶段,这使得生成的类在编译阶段可用:
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>pre-compile</id>
<phase>generate-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>process-sources</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>com.example.MyCodeGenerator</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)