For some reason I am getting a runtime error while loading fonts from assets. I have read couple of questions here saying that assets folder needs to be placed in src/main/
.
I found out, I have no main
folder in my folder structure and when I tried to put it just to the src
folder I am having the same issue.
Any idea why I have no main
, and in general I seem to have strange folder structure? It might be that I am having parse.com skeleton application. How to fix it?
The way I am trying to access to the font file:
Typeface myTypeface = Typeface.createFromAsset(getAssets(), "assets/charming_font.ttf");
I have checked this
And this is my folder structure:
My build.gradle
:
apply plugin: 'com.android.application'
apply plugin: 'com.parse'
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.parse.com/repo' }
}
dependencies {
classpath 'com.parse.tools:gradle:1.+'
}
}
dependencies {
compile 'com.parse.bolts:bolts-android:1.2.0'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
compile fileTree(dir: 'libs', include: 'ParseCrashReporting-*.jar')
compile fileTree(dir: 'libs', include: 'gson-2.3.1.jar')
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro', 'proguard-rules-new.pro'
}
}
}
}
Android project view:
答案 0 :(得分:1)
I have also tried adding this to sourceSets : assets.srcDirs = ['assets'] but it didn't help.
That is the right answer, but then assets/
would be a peer of java/
, not a subdirectory of it.