簡體   English   中英

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

[英]declaring android.support.v7.app in gradle

我在AppCompatGradle遇到問題,首先是我的應用程序只有一個Gradle用於模塊,而沒有像下面顯示的圖片那樣有Gradle用於應用程序,我的其他應用程序中有2個漸變,並且如果其重要項目使用蝕然后我遷移到android studio:

一gra的問題

第二個是當我進行一項活動時,出現錯誤

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有某種關系。

您的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'
}

刪除整個依賴項排除:

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

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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM