在gradle中声明android.support.v7.app

时间:2016-03-29 07:58:31

标签: android eclipse gradle android-appcompat

我对AppCompatGradle有疑问,第一个问题是我的应用只有一个Gradle用于模块,并且没有Gradle用于app我在下面显示的图片 我在其他应用程序中有两个渐变,如果它的重要项目是使用eclipse编写的,那么我将迁移到android studio:

issue of having one gradle

,第二个是当我运行我的一个活动时,我得到了错误

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

这是我的活动代码导致错误:

 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有关。

3 个答案:

答案 0 :(得分:0)

你的Logcat抛出

clear 
input rating_id RatingTeacher RatedTeacher Rating str8 SDate 
1 15 12 1 "1/1/2010"
2 12 11 2 "1/2/2010"
3 14 11 3 "1/2/2010"
4 14 13 2 "1/5/2010"
5 19 11 4 "1/6/2010"
6 11 13 1 "1/7/2010"
end 
gen Date = daily(SDate, "MDY") 
sort Date 

gen Wanted = . 
quietly forval i = 1/`=_N' { 
    count if Date <  Date[`i'] & RatedT == RatingT[`i'] 
    replace Wanted = r(N) in `i' 
} 

list, sep(0)  

     +---------------------------------------------------------------------+
     | rating~d   Rating~r   RatedT~r   Rating      SDate    Date   Wanted |
     |---------------------------------------------------------------------|
  1. |        1         15         12        1   1/1/2010   18263        0 |
  2. |        2         12         11        2   1/2/2010   18264        1 |
  3. |        3         14         11        3   1/2/2010   18264        0 |
  4. |        4         14         13        2   1/5/2010   18267        0 |
  5. |        5         19         11        4   1/6/2010   18268        0 |
  6. |        6         11         13        1   1/7/2010   18269        3 |
     +---------------------------------------------------------------------+

您应该删除 java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV14

最后

module: 'support-v4'

然后 configurations { all*.exclude group: 'com.android.support' } 您的项目。

你可以删除它,不需要

Clean-Rebuild-Sync

答案 1 :(得分:0)

删除整个依赖项排除:

configurations {
   all*.exclude group: 'com.android.support', module: 'support-v4'
}

答案 2 :(得分:0)

<强>的build.gradle:

//...
defaultConfig {
    multiDexEnabled = true
}

dependencies {
    //...
    compile 'com.android.support:multidex:1.0.1'
    //...
}

申请类:

public class App extends Application {
    //...
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }
    //...
}

<强>的AndroidManifest.xml:

<application
    android:name="com.company.App">
    <!-- ... -->
</application>