1

i have problem with AppCompat and Gradle , first issue is my app have just one Gradle for module , and doesn't have Gradle for app like the picture i show below i had 2 gradles in my other apps and if its important project is written using eclipse then i migrated to android studio :

issue of having one gradle

and second one is when i run one of my activities i get the error

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

and here is my activity code whic cause error :

 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();
}}

and the my gradle content is also here :

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 {
}

i already added appcompact for my project but the error i think is related to app compact somehow .

USER9561
  • 1,084
  • 3
  • 15
  • 41

3 Answers3

0

Your Logcat throws

 java.lang.NoClassDefFoundError: android.support.v7.app.AppCompatDelegateImplV14

You should remove module: 'support-v4'

Finally

    configurations {
        all*.exclude group: 'com.android.support'
}

Then Clean-Rebuild-Sync Your Project .

You can remove this, No need

 configurations {
 all*.exclude group: 'com.android.support', module: 'support-v4'
}
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
  • Error:(44, 23) error: cannot access AlertDialog class file for android.support.v7.app.AlertDialog not found Error:Execution failed for task ':compileDebugJavaWithJavac'. > Compilation failed; see the compiler error output for details. D:\Android WorkSpace\Flashlight Pro(Base)\src\com\soheil\prolightfa\color.java – Soheil Afshari Mar 29 '16 at 08:30
  • @SoheilAfshari http://stackoverflow.com/questions/24998368/the-import-android-support-v7-cannot-be-resolved – IntelliJ Amiya Mar 29 '16 at 08:31
  • Read http://stackoverflow.com/questions/24651232/the-import-android-support-v7-app-cannot-be-resolved – IntelliJ Amiya Mar 29 '16 at 08:33
  • 1
    leaning and rebuilding again fixed it – Soheil Afshari Mar 29 '16 at 08:46
0

Remove the whole dependency exclusion:

configurations {
   all*.exclude group: 'com.android.support', module: 'support-v4'
}
szym
  • 5,606
  • 28
  • 34
0

build.gradle:

//...
defaultConfig {
    multiDexEnabled = true
}

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

Application class:

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>
Volodymyr Kulyk
  • 6,455
  • 3
  • 36
  • 63