问题描述
我想在不同于活动的文件夹中设置类。
当前文件夹结构:
I want to set up classes in different folders than activities.Current folder structure:
-> APP
-> Manifests
-> Java
-> com.test.testing
-> classes
auth.java
home_activity
-> libs
auth.java
package com.test.testing;
// error here: Package name ‘com.test.testing’ does not correspond to file path.
public class auth{
public void auth(){}
}
另外,我无法在活动中调用此类:
Plus, I can't call this class in activity:
import classes.auth;
所以我去构建gradle这是我的配置:
So I went to build gradle an this are my configurations:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.test.testing"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
java.srcDirs = ['src/main/java', 'java/', 'src/main/java/com/test/testing/classes']
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
}
}
}
Android Studio是李关于文件夹结构有点混乱,我们有几个选项可供选择,我不知道它们中的一些是什么。
在我的例子中,我将文件夹classes添加为Java Folder。
Android Studio is a little bit confusing about folder structures, we have several options to chose and I have no clue what some of them do.In my case, I added the folder "classes" as "Java Folder".
编辑1:
提示是创建一个包而不是一个文件夹。
所以我创建了包和一个新文件。自动,android studio将此信息填入 auth.java ;
package com.test.testing.classes;
public class auth {
}
会发生什么事情,我仍然无法将课程导入活动。
当我开始输入时(在活动中)导入类
它出现在文档帮助中,但它没有任何关联的对象,它说:
What happens is that I'm still unable to import the class into the activities.Althought when I start typing (in the activity) import classes
it appears as a documentation help but it doesn't have any object associated, that said:
import classes.auth;
给出错误。
我又来了构建Gradle文件并且它没有向 java.srcDirs
添加任何内容:
I went again to build Gradle file and it didn't add anything to the java.srcDirs
:
sourceSets {
main {
java.srcDirs = ['java/', 'src/main/java']
}
}
编辑2:
导入的解决方案
问题是字符串。
而不是
EDIT 2:The solution to the import
problem was the string.Instead of
import classes.auth;
应该是:
import com.test.testing.classes.auth;
推荐答案
选择套餐
来自上面的列表(在快照中)
Select Package
from the List above (in your snap shot)
这篇关于在Android Studio中添加类的文件夹的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!