简体   繁体   English

Android Studio无效的文件夹结构

[英]Android studio invalid folder structure

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/ . 我在这里读了几个问题,说资产文件夹需要放在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. 我发现,我的文件夹结构中没有main文件夹,当我尝试将其仅放置到src文件夹时,我遇到了同样的问题。

Any idea why I have no main , and in general I seem to have strange folder structure? 知道为什么我没有main ,而且总的来说我似乎有奇怪的文件夹结构吗? It might be that I am having parse.com skeleton application. 可能是我有parse.com框架应用程序。 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 : 我的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: Android项目视图:

在此处输入图片说明

I have also tried adding this to sourceSets : assets.srcDirs = ['assets'] but it didn't help. 我也尝试将其添加到sourceSets:assets.srcDirs = ['assets'],但没有帮助。

That is the right answer, but then assets/ would be a peer of java/ , not a subdirectory of it. 这是正确的答案,但是assets/将是java/同级物,而不是它的子目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM