对于那些想要隔离Java并给它快速测试的时候..
您可以像在Eclipse中一样在Android Studio中运行非Android Java项目吗?
我有一个项目A,它包含一些java文件和一个类路径资源R.txt.在项目中我使用ClassLoader.getSystemResource("R.txt"); 检索R.txt.
然后我有一个项目B,其中包含项目A的jar文件.现在getSystemResource("R.txt")找不到文本文件(是的,它仍然在jar文件的根目录中).即使尝试在其他网站上建议的"/R.txt"也行不通.有任何想法吗?
我导入了一个由亚马逊编码的Android样本,涉及我从这里获得的AWS的DynamoDB,可能是为Eclipse编写的:https: //github.com/awslabs/aws-sdk-android-samples/tree/master/DynamoDBMapper_UserPreference
由于Android Studio(0.8.1)使用gradle而不是ant,因此在导入时自然会在dir结构方面自动移动,所以(部分)它看起来像这样:

PropertyLoader获取从AwsCredentials.properties连接到数据库DynamoDB所需的TVM凭据信息.相关方法:
public class PropertyLoader {
private boolean hasCredentials = false;
private String tokenVendingMachineURL = null;
private boolean useSSL = false;
private String testTableName = null;
private static PropertyLoader instance = null;
public static PropertyLoader getInstance() {
if ( instance == null ) {
instance = new PropertyLoader();
}
return instance;
}
public PropertyLoader() {
try {
Properties properties = new Properties();
properties.load( this.getClass().getResourceAsStream( "AwsCredentials.properties" ) );
this.tokenVendingMachineURL = properties.getProperty( "tokenVendingMachineURL" );
this.useSSL = Boolean.parseBoolean( …Run Code Online (Sandbox Code Playgroud)