Не удалось найти класс "android.support.design.widget.CoordinatorLayout" с помощью Buck

Я пытаюсь заставить Бака работать с шаблоном приложения balnk из Android Studio.

apps/snappy/BUCK

android_binary(
  name = 'main',
  manifest = 'AndroidManifest.xml',
  keystore = '//keystores:debug',
  package_type = 'debug',
  deps = [
    '//java:main',
    '//res:res',
    '//keystores:debug',
  ],
)

res/snappy/layout/activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.whitedrop.snappy.MainActivity">

    ....

</android.support.design.widget.CoordinatorLayout>

res/BUCK

android_resource(
  name = 'res',
  res = 'snappy',
  package = 'com.whitedrop.snappy',
  deps = [
  '//libs:appcompat-v7',
  '//libs:design'
  ],
  visibility = [
    'PUBLIC',
  ]
)

libs/BUCK

android_prebuilt_aar(
  name = 'appcompat-v7',
  aar = 'appcompat-v7-23.0.1.aar',
  visibility = ['PUBLIC']
)
android_prebuilt_aar(
  name = 'design',
  aar = 'design-23.0.1.aar',
  visibility = ['PUBLIC']
)

выход

                    Process com.whitedrop.snappy created for activity com.whitedrop.snappy/.MainActivity
                    PID: 2449   UID:    GIDs: 

ActivityManager  I  Start proc 2449:com.whitedrop.snappy/u0a61 for activity com.whitedrop.snappy/.MainActivity
            art  I  Rejecting re-init on previously-failed class java.lang.Class<android.support.design.widget.CoordinatorLayout>
 AndroidRuntime  D  Shutting down VM
                 E  FATAL EXCEPTION: main
                 E  Process: com.whitedrop.snappy, PID: 2449
                 E  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.whitedrop.snappy/com.whitedrop.snappy.MainActivity}: android.view.InflateExcept
                    ion: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
                 ...E      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
                 E      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
                 E  Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.CoordinatorLayout
                 E      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:757)
                 ....
                 E      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
                 E      ... 10 more
                 E  Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.CoordinatorLayout" on path: DexPathList[[zip file "/data
                    /app/com.whitedrop.snappy-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
                 E      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                 ...
                 E      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
                 E      ... 19 more
                 E      Suppressed: java.lang.NoClassDefFoundError: android.support.design.widget.CoordinatorLayout
                 E          at dalvik.system.DexFile.defineClassNative(Native Method)
                 E ....     at dalvik.system.DexPathList.findClass(DexPathList.java:321)
                 E          at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
                 E          ... 23 more
                 E      Suppressed: java.lang.ClassNotFoundException: android.support.design.widget.CoordinatorLayout
                 E          at java.lang.Class.classForName(Native Method)
                 E          at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
                 E          at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
                 E          at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                 E          ... 22 more
                 E      Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
ActivityManager  W    Force finishing activity 1 com.whitedrop.snappy/.MainActivity

РЕДАКТИРОВАТЬ: мой apk содержит класс CoordinatorLayout в своем файле dex между прочим

EDIT2: полный код можно найти здесь https://github.com/vinz243/snappy

EDIT3: попытался расширить с AppCompatActivity:

vinz243@vm:~/snappy$ buck build app
[-] PROCESSING BUCK FILES...FINISHED 0.1s [100%]
[+] DOWNLOADING... (0.00 B/S, TOTAL: 0.00 B, 0 Artifacts)
[+] BUILDING...0.3s [67%] (16/20 JOBS, 0 UPDATED, 0.0% CACHE MISS)
 |=> IDLE
 |=> IDLE
 |=> //java:main...  0.2s (running javac[0.2s])
 |=> IDLE
/home/vinz243/snappy/java/com/whitedrop/snappy/MainActivity.java:12: error: cannot access android.support.v4.app.TaskStackBuilder
public class MainActivity extends AppCompatActivity {
       ^
  class file for android.support.v4.app.TaskStackBuilder not found
/home/vinz243/snappy/java/com/whitedrop/snappy/MainActivity.java:14: error: method does not override or implement a method from a supertype
    @Override
        ^
/home/vinz243/snappy/java/com/whitedrop/snappy/MainActivity.java:16: error: cannot find symbol
        super.onCreate(savedInstanceState);
                ^
  symbol:   variable super
  location: class com.whitedrop.snappy.MainActivity
/home/vinz243/snappy/java/com/whitedrop/snappy/MainActivity.java:17: error: cannot find symbol
        setContentView(R.layout.activity_main);
                ^
  symbol:   method setContentView(int)
  location: class com.whitedrop.snappy.MainActivity
/home/vinz243/snappy/java/com/whitedrop/snappy/MainActivity.java:20: error: method does not override or implement a method from a supertype
    @Override
        ^
/home/vinz243/snappy/java/com/whitedrop/snappy/MainActivity.java:23: error: cannot find symbol
        getMenuInflater().inflate(R.menu.activity_main, menu);
                ^
  symbol:   method getMenuInflater()
  location: class com.whitedrop.snappy.MainActivity
Errors: 6. Warnings: 0.

Вот MainActivity.java:

package com.whitedrop.snappy;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}

РЕДАКТИРОВАТЬ 5:

Исправлена ​​ошибка выше, добавив поддержку v4 в deps. Теперь я получаю при запуске:

 E  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.whitedrop.snappy/com.whitedrop.snappy.MainActivity}: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
 E      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
 E  Caused by: android.view.InflateException: Binary XML file line #36: Error inflating class android.support.v7.widget.Toolbar
 E      at android.view.LayoutInflater.createView(LayoutInflater.java:633)
 E  Caused by: java.lang.reflect.InvocationTargetException
 E      at java.lang.reflect.Constructor.newInstance(Native Method)
 E      at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
 E      at android.view.LayoutInflater.createView(LayoutInflater.java:607)
 E      ... 24 more
 E  Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/graphics/drawable/VectorDrawableCompat;
 E      at android.support.v7.widget.AppCompatDrawableManager$VdcInflateDelegate.createFromXmlInner(AppCompatDrawableManager.java:891)
 E  Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.graphics.drawable.VectorDrawableCompat" on path: DexPathList[[zip file
     "/data/app/com.whitedrop.snappy-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
 E      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)

3 ответа

Решение

Убедитесь, что версии, которые вы упомянули в вашем BUCK конфиг правильный.

В коде, которым вы поделились в своем вопросе, я вижу v23.0.1 для поддержки и проектирования библиотек. В вашем github-хранилище я вижу v23.4.0,

Я подозреваю, что это причина. Перейдите на правильную версию, включенную в папку libs, и посмотрите, работает ли она.

Обновление в ответ на правку 5 в вашем вопросе:

Следующие две зависимости помогут решить VectorDrawableCompat ClassNotFoundException, Включите их подходящим способом для BUCK.

compile 'com.android.support:support-vector-drawable:23.4.0'
compile 'com.android.support:animated-vector-drawable:23.4.0'

Попробуйте расширить MainActivity в AppCompatActivity вместо Activity

А потом чистая установка.

Не связано с BUCK, но для меня, я столкнулся с этой ошибкой при использовании смеси androidx а также android.support.v7 библиотеки. Смотрите мое решение для этой версии этой ошибки здесь: /questions/32206269/oshibka-naduvaniya-klassa-androidsupportdesignwidgetcoordinatorlayout-i-classnotfoundexception-androidsupportdesignrstyleable/32206303#32206303

Другие вопросы по тегам