I imported an Android sample coded by Amazon involving AWS\'s DynamoDB which I got from here and was presumably written for Eclipse: https://github.com/awslabs/aws-sdk-andro
For up to a day I was struggling with this as well. And finally I was able to resolve this very neatly. The problem is not in the JAVA but in the all project structure. E.g. in Android Studio the whole project is under src/main/java
whereas main
is a flavour
of the project. So if you've file(-s) to read from in source's package (e.g.) com/my/example/app
you have to edit the build.gradle
file for read (clazz.getResourceAsStream(file)
) to work properly. I.e. under android
define sourceSets
like this:
android {
/* ... Your stuff ... */
sourceSets {
// Lets have two flavours to make it more clear
main {
resources.srcDirs = ['src/main/java']
}
flavourFoo {
resources.srcDirs = ['src/flavourFoo/java']
}
}
}
Hope this helps!
Created a dir called resources under /src/main/ and placed AwsCredentials.properties there and used
properties.load( PropertyLoader.class.getClassLoader().getResourceAsStream( "AwsCredentials.properties" ) );
instead of
properties.load( this.getClass().getResourceAsStream("AwsCredentials.properties" ) );
Not as elegant as I would like, but it works.