我对 AppCompat
有疑问和 Gradle
,第一个问题是我的应用只有一个 Gradle
对于 module ,并且没有 Gradle
对于像我在下面显示的图片这样的应用程序
我在我的其他应用程序中有 2 个 gradles,如果它的重要项目是使用 eclipse 编写的,那么我迁移到 android studio:
第二个是当我运行我的一项 Activity 时出现错误
03-29 12:15:30.461 18276-18276/com.soheil.prolightfa E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.soheil.prolightfa, PID: 18276
java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV14
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:135)
at android.support.v7.app.AppCompatDelegate.create(AppCompatDelegate.java:126)
at android.support.v7.app.AppCompatDialog.getDelegate(AppCompatDialog.java:142)
at android.support.v7.app.AppCompatDialog.<init>(AppCompatDialog.java:48)
at android.support.v7.app.AlertDialog.<init>(AlertDialog.java:92)
at android.support.v7.app.AlertDialog$Builder.create(AlertDialog.java:882)
at com.flask.colorpicker.builder.ColorPickerDialogBuilder.build(ColorPickerDialogBuilder.java:223)
at com.soheil.prolightfa.color.onCreate(color.java:43)
at android.app.Activity.performCreate(Activity.java:6500)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3078)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3224)
at android.app.ActivityThread.access$1000(ActivityThread.java:198)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1682)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6843)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199
这是我的导致错误的 Activity 代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_color);
final ImageView imgbck= (ImageView) findViewById(R.id.imageView4);
ColorPickerDialogBuilder
.with(getApplicationContext())
.setTitle("Choose color")
//.initialColor(currentBackgroundColor)
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(12)
.setOnColorSelectedListener(new OnColorSelectedListener() {
@Override
public void onColorSelected(int selectedColor) {
// toast("onColorSelected: 0x" + Integer.toHexString(selectedColor));
}
})
.setPositiveButton("ok", new ColorPickerClickListener() {
@Override
public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) {
imgbck.setBackgroundColor(selectedColor);
}
})
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.build()
.show();
}}
我的 gradle 内容也在这里:
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}
buildscript {
repositories {
maven { url "https://jitpack.io" }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
apply plugin: 'com.android.application'
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
dependencies {
compile 'com.github.QuadFlask:colorpicker:0.0.10'
compile 'com.android.support:appcompat-v7:23.1.1'
}
android {
compileSdkVersion 23
buildToolsVersion '23.0.1'
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
defaultConfig {}
productFlavors {
}
buildTypes {
}
我已经为我的项目添加了 appcompact,但我认为该错误与 app compact 不知何故有关。
最佳答案
你的 Logcat 抛出
java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV14
您应该删除
module: 'support-v4'
最后
configurations {
all*.exclude group: 'com.android.support'
}
那么
Clean-Rebuild-Sync
你的项目。可以去掉,不需要
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
关于android - 在 gradle 中声明 android.support.v7.app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36278585/