注解无效

  1. 检查下你的工程中有没有使用apply plugin: 'android-apt',如果有的话将其转换为annotationProcessor。

  2. 检查下annotationProcessor 和 compile 版本是否一致,不一致的话将导致生成代理文件失败

  3. 如果你是Android studio的module中引用的Aria,那么你还需要再app模块中添加同样的导入代码

     compile 'com.arialyy.aria:aria-core:{version code}'
     annotationProcessor 'com.arialyy.aria:aria-compiler:{version code}'
    
  4. 如果以上设置都无效或控制台打印下面的错误

    Annotation processors must be explicitly declared now.  The following dependencies on the compile classpath are found to 
    contain annotation processor.  Please add them to the annotationProcessor configuration.
    

    请在app的build.gradle文件的defaultConfig块中添加以下代码

    android {
      compileSdkVersion 26
      buildToolsVersion "26.0.2"
      defaultConfig {
        ....
        javaCompileOptions {
          annotationProcessorOptions {
            includeCompileClasspath true
          }
        }
      }
      ...
    }
    
  5. 如果是使用的kotlin,那请去掉Aria注解方法的internal修饰符

  6. 如果使用的是低版本的kotlin,请尝试将kotlin升级为最新版本

  7. 注册的类中至少有一个被@Download@Upload@DownloadGroup注解的方法(原则是:哪个地方有注解就在哪个地方进行注册)

      public class MainActivity extends Activity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          // 进行注册
          Aria.download(this).register(); 
        }
    
        // 如果当前类中没有方法被`@Download`或`@Upload`或`@DownloadGroup`注解,那么就会提示没有Aria的注解方法 
        @Download.onTaskComplete
        void onComplete(DownloadTask task) {
          Log.d(TAG, "complete");
        }
    
      }
    
  8. Fragment\ Dialog\Service\PopupWindow等类中,不要使用Context或Activity等类

    public class Fragmnt extends Fragment{
      @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
          @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.activity_main, container);
        Aria.download(this).register(); // 正确的写法
        Aria.download(getActivity()).register(); // 错误
        Aria.download(getContext()).register(); // 错误
        return rootView;
      }
    }
    
  9. 如果都不是的话,build文件时,点击as右下角的gradle console窗口,看看报什么错误(如果有错误,可以的话,麻烦在Issues留言给我)

  10. 终极方案,不使用注解,直接使用回调,需要3.8.11以上版本

    public class A extends Activity implements DownloadTaskListener{
    @Override protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Aria.download(this).register();
    }
    }
    

    支持的回调有: | 任务类型 | 事件回调 | | ---- | ---- | | 普通下载任务 | DownloadTaskListener | | 组合任务 | DownloadGroupTaskListener | | 组合任务子任务 | SubTaskListener | | M3U8 peer | M3U8PeerTaskListener | | 上传任务 | UploadTaskListener |

Copyright © 2018 laoyuyu. | 蜀ICP备17031160号.            更新时间: 2020-08-11

results matching ""

    No results matching ""