尝试使用Android Studio 3 Canary 5与Architecture Components和Kotlin构建示例时会发出此警告.
谁能告诉我原因?
谢谢,Ove
编辑#1:这是Dan Lew不久前制作的一个样本
https://github.com/dlew/android-architecture-counter-sample
的build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 25
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
applicationId "net.danlew.counter"
minSdkVersion 23
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
compile "com.android.support:recyclerview-v7:${rootProject.ext.supportLibVersion}"
compile "com.android.support:design:${rootProject.ext.supportLibVersion}"
compile "com.android.support:cardview-v7:${rootProject.ext.supportLibVersion}"
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile …Run Code Online (Sandbox Code Playgroud) android kotlin android-studio android-architecture-components
成功进行基本身份验证后,我想添加一个帐户供以后使用.当我尝试使用以下代码创建此帐户时:
AccountManager accountManager = AccountManager.get(getBaseContext());
final Account basicAccount = new Account(mEmail, "com.example");
accountManager.addAccountExplicitly(basicAccount, mPassword, null);
Run Code Online (Sandbox Code Playgroud)
当调用addAccountExplicitly(...)时,应用程序崩溃并出现以下错误:
E/AndroidRuntime: FATAL EXCEPTION: main
E/AndroidRuntime: Process: com.example, PID: 19094
E/AndroidRuntime: java.lang.SecurityException: uid 10107 cannot explicitly add accounts of type: com.example
E/AndroidRuntime: at android.os.Parcel.readException(Parcel.java:1599)
E/AndroidRuntime: at android.os.Parcel.readException(Parcel.java:1552)
E/AndroidRuntime: at android.accounts.IAccountManager$Stub$Proxy.addAccountExplicitly(IAccountManager.java:890)
E/AndroidRuntime: at android.accounts.AccountManager.addAccountExplicitly(AccountManager.java:712)
E/AndroidRuntime: at com.example.LoginActivity$UserLoginTask.onPostExecute(LoginActivity.java:244)
E/AndroidRuntime: at com.example.LoginActivity$UserLoginTask.onPostExecute(LoginActivity.java:209)
E/AndroidRuntime: at android.os.AsyncTask.finish(AsyncTask.java:651)
E/AndroidRuntime: at android.os.AsyncTask.-wrap1(AsyncTask.java)
E/AndroidRuntime: at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)
E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime: at android.os.Looper.loop(Looper.java:148)
E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5417)
E/AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
E/AndroidRuntime: …Run Code Online (Sandbox Code Playgroud) 升级到3.0后,Android Studio开始抱怨矢量绘图中的长路径.
警告说:
很长的矢量路径(7958个字符),这对性能不利.考虑降低精度,删除次要细节或光栅化矢量.less ...(⌘F1)使用长向量路径对性能不利.有几种方法可以缩短pathData:*使用较少的精度*删除一些细节*使用Android Studio矢量转换工具*光栅化图像(转换为PNG)
文档https://developer.android.com/guide/topics/graphics/vector-drawable-resources.html向我们展示了如何在我们的应用程序中使用矢量绘图,并通过png等推荐它.
我一直在使用Android Studio矢量转换工具和这个优秀的服务将SVG转换为矢量绘图:http: //inloop.github.io/svg2android/
是否还有其他服务可以减少矢量可绘制的复杂性?我在哪里可以找到关于我的矢量绘图可以"先进"的指导方针?
我正在尝试使用新的Android数据绑定库,并尝试使用所选值填充微调器时出现以下错误.
错误消息(在Android Studio中编译期间):
错误:任务':app:compileDebugJavaWithJavac'的执行失败.java.lang.RuntimeException:发现数据绑定错误.****/数据绑定错误****消息:无法找到参数类型为java.lang.String的属性'app:selection'的setter.file:/Users/ove/Code/AndroidStudio/Samples/Receipts/app/src/main/res/layout/dialogfragment_inputamount_db.xml loc:40:29 - 40:44****\data binding error****
我的布局文件看起来如下(不完整):
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="receipt"
type="com.example.model.Receipt" />
</data>
</LinearLayout>
<Spinner
android:layout_width="wrap_content"
android:id="@+id/currency"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
android:entries="@array/currency_array"
app:selection="@{receipt.currency}" />
</LinearLayout>
</layout>
Run Code Online (Sandbox Code Playgroud)
那些设法获得数据绑定与旋转器一起工作的人?
奥维
我有一个列表对象Recyclerview.当长按一个项目时,我想显示一个对话框,其中包含单击该项目的数据.
所述Recyclerview使用数据对每个项目结合和我用Log长按时是能够显示从所选择的项目的数据.
但是,在尝试显示对话框时,您需要访问Activity,不建议在ViewModel对象中使用.
那么如何显示对话框?
谢谢,Ove
我有一个包含回收视图的片段。这个 recyclerview 使用数据绑定绑定到我的视图模型。
问题; 我在尝试启动片段时遇到以下异常:
FATAL EXCEPTION: main
Process: no.inforte.demo, PID: 3134
java.lang.IllegalArgumentException: No view found for id 0x7f0d0074 (no.inforte.demo:id/content_frame) for fragment CategoryListFragment2{6db9671 #1 id=0x7f0d0074 CATEGORYLISTFRAGMENT}
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1059)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
...
...
Run Code Online (Sandbox Code Playgroud)
该错误正确地表明“content_frame”不存在。该视图位于 MainActivity.java 类的布局中,作为我的片段容器。
由于我使用数据绑定,因此我使用 DataBindingUtil.setContentView 方法:
private void initDataBinding() {
Log.d(TAG, "initDataBinding");
mCategoryListFragmentBinding = DataBindingUtil.setContentView(getActivity(), R.layout.category_list_fragment);
mCategoryListViewModel = new CategoryListViewModel(mCategoryListView, getContext());
mCategoryListFragmentBinding.setCategoryListViewModel(mCategoryListViewModel);
}
Run Code Online (Sandbox Code Playgroud)
如何解决?
更多信息:
这就是我从 MainActivity 启动此片段的方式:
CategoryListFragment2 categoryListFragment = new CategoryListFragment2();
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.content_frame, categoryListFragment, FRAGMENT_TAG_CATEGORYLIST)
.commit();
getSupportFragmentManager().executePendingTransactions();
Run Code Online (Sandbox Code Playgroud)
这是我的片段布局:
<?xml version="1.0" encoding="utf-8"?>
<layout
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" …Run Code Online (Sandbox Code Playgroud) 我正在使用架构组件创建一个应用程序.
调试版本运行正常,但在测试版本APK时,应用程序崩溃了下面的堆栈跟踪.
奇怪的是,我有6个视图模型的片段以相同的方式设置.其中2个崩溃,其中4个按预期工作.
该项目没有进行任何进展.
我正在使用具有以下依赖项的体系结构组件:
compile "android.arch.lifecycle:runtime:${arch}"
compile "android.arch.lifecycle:extensions:${arch}"
annotationProcessor "android.arch.lifecycle:compiler:${arch}"
Run Code Online (Sandbox Code Playgroud)
架构组件的版本是'1.0.0-beta2'(arch ='1.0.0-beta2').如果我尝试架构组件的版本是'1.0.0-rc1'(arch ='1.0.0-rc1'),我会遇到同样的问题.
我从片段中实例化我的viewmodel,如下所示:
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
otherWorkViewModel = ViewModelProviders.of(this).get(OtherWorkViewModel.class);
if (savedInstanceState == null) {
// Check for arguments to fragment (section object and position in list)
if (getArguments() != null) {
OtherWork otherWork = (OtherWork) getArguments().get("otherWork");
otherWorkViewModel.setOtherWork(otherWork);
int position = getArguments().getInt("position");
otherWorkViewModel.setPosition(position);
}
}
}
Run Code Online (Sandbox Code Playgroud)
在运行库代码以实例化viewmodel时,应用程序崩溃时出现以下异常:
10-20 08:41:03.555 2102-2102/no.example.thisapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: no.example.thisapp, PID: 2102
java.lang.RuntimeException: Cannot create an instance of …Run Code Online (Sandbox Code Playgroud) 将项目升级为使用API级别为27.0.0(Android 8.1)的Android Studio 3.0之后,我收到了许多与片段中使用getActivity()有关的新的掉线警告(我认为这很好)。
例子:
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
getActivity().getMenuInflater().inflate(R.menu.pavingreport_dialog_menu, menu);
Run Code Online (Sandbox Code Playgroud)
这两个示例都抱怨存在空异常。
例:
Method invocation 'getMenuInflater' may produce 'java.lang.NullPointerException'
Run Code Online (Sandbox Code Playgroud)
我知道我可以通过将活动添加为字段并在onCreate或其他过程中对其进行初始化来解决此问题,但这只会删除警告...
问题:
似乎我的设备上的定期作业数量(模拟器和真实作业)在应用更新时不断增加.如果我使用Android Studio安装或首先创建签名的APK,然后通过adb(adb install -r name.apk)更新,则无关紧要.
使用命令'adb shell dumpsys jobscheduler'会产生以下结果:
Registered jobs:
108..:[ComponentInfo{com.google.android.apps.maps/com.google.android.apps.gmm.offline.OfflineAutoUpdateJobService},jId=2131624035,u0,R=(23:32:44,47:32:44),N=1,C=true,I=true,F=0,P=true,ANI=true]
148..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=61,u0,R=(07:54,17:54),N=0,C=false,I=false,F=0,P=false,ANI=true]
160..:[ComponentInfo{android/com.android.server.backup.FullBackupJob},jId=20536,u0,R=(none,none),N=2,C=true,I=true,F=0,P=false,ANI=true]
192..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=50,u0,R=(1:30:00,1:40:00),N=0,C=false,I=false,F=0,P=false,ANI=true]
206..:[ComponentInfo{android/com.android.server.os.BackgroundCompactionService},jId=802,u0,R=(50:21,none),N=0,C=false,I=true,F=0,P=false,ANI=true]
215..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=60,u0,R=(37:54,47:54),N=0,C=false,I=false,F=0,P=false,ANI=true]
262..:[ComponentInfo{com.android.providers.downloads/com.android.providers.downloads.DownloadIdleService},jId=1,u0,R=(-20:38,3:25:13),N=0,C=true,I=true,F=0,P=true,ANI=true]
291..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=9,u0,R=(12:47,22:47),N=0,C=false,I=false,F=0,P=false,ANI=true]
312..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=37,u0,R=(12:57,22:57),N=0,C=false,I=false,F=0,P=false,ANI=true]
456..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=38,u0,R=(1:22:56,1:32:56),N=0,C=false,I=false,F=0,P=true,ANI=true]
540..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=39,u0,R=(22:46,32:46),N=0,C=false,I=false,F=0,P=true,ANI=true]
577..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=57,u0,R=(03:34,13:34),N=0,C=false,I=false,F=0,P=false,ANI=true]
639..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=8,u0,R=(22:47,32:47),N=0,C=false,I=false,F=0,P=true,ANI=true]
663..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=56,u0,R=(33:34,43:34),N=0,C=false,I=false,F=0,P=false,ANI=true]
862..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=43,u0,R=(23:11,33:11),N=0,C=false,I=false,F=0,P=true,ANI=true]
864..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=32,u0,R=(22:56,32:56),N=0,C=false,I=false,F=0,P=true,ANI=true]
984..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=42,u0,R=(1:22:46,1:32:46),N=0,C=false,I=false,F=0,P=true,ANI=true]
102..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=49,u0,R=(00:00,10:00),N=0,C=false,I=false,F=0,P=false,ANI=true]
104..:[ComponentInfo{android/com.android.server.pm.BackgroundDexOptService},jId=800,u0,R=(-20:38,none),N=0,C=true,I=true,F=0,P=false,ANI=true]
114..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=44,u0,R=(23:11,33:11),N=0,C=false,I=false,F=0,P=true,ANI=true]
124..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=53,u0,R=(19:50,29:50),N=0,C=false,I=false,F=0,P=false,ANI=true]
124..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=33,u0,R=(12:57,22:57),N=0,C=false,I=false,F=0,P=false,ANI=true]
126..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=62,u0,R=(1:37:54,1:47:54),N=0,C=false,I=false,F=0,P=false,ANI=true]
130..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=41,u0,R=(12:47,22:47),N=0,C=false,I=false,F=0,P=false,ANI=true]
131..:[ComponentInfo{android/com.android.server.backup.KeyValueBackupJob},jId=20537,u0,R=(3:42:43,23:39:25),N=1,C=true,I=false,F=0,P=false,ANI=true]
161..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=51,u0,R=(29:50,39:50),N=0,C=false,I=false,F=0,P=false,ANI=true]
162..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=36,u0,R=(22:56,32:56),N=0,C=false,I=false,F=0,P=true,ANI=true]
165..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=52,u0,R=(29:50,39:50),N=0,C=false,I=false,F=0,P=false,ANI=true]
170..:[ComponentInfo{com.google.android.apps.maps/com.google.android.apps.gmm.offline.OfflineAutoUpdateJobService},jId=2131624034,u0,R=(17:39:42,18:09:42),N=1,C=true,I=true,F=0,P=true,ANI=true]
171..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=54,u0,R=(1:29:50,1:39:50),N=0,C=false,I=false,F=0,P=false,ANI=true]
175..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=47,u0,R=(30:00,40:00),N=0,C=false,I=false,F=0,P=false,ANI=true]
197..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=58,u0,R=(1:33:34,1:43:34),N=0,C=false,I=false,F=0,P=false,ANI=true]
208..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=34,u0,R=(1:22:56,1:32:56),N=0,C=false,I=false,F=0,P=true,ANI=true]
209..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=10,u0,R=(1:22:57,1:32:57),N=0,C=false,I=false,F=0,P=true,ANI=true]
213..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=48,u0,R=(30:00,40:00),N=0,C=false,I=false,F=0,P=false,ANI=true]
215..:[ComponentInfo{android/com.android.server.MountServiceIdler},jId=808,u0,R=(17:09:17,none),N=0,C=true,I=true,F=0,P=false,ANI=true]
218..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=55,u0,R=(33:34,43:34),N=0,C=false,I=false,F=0,P=false,ANI=true]
225..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=31,u0,R=(22:57,32:57),N=0,C=false,I=false,F=0,P=true,ANI=true]
242..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=35,u0,R=(22:57,32:57),N=0,C=false,I=false,F=0,P=true,ANI=true]
252..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=40,u0,R=(22:46,32:46),N=0,C=false,I=false,F=0,P=true,ANI=true]
255..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=59,u0,R=(37:54,47:54),N=0,C=false,I=false,F=0,P=false,ANI=true]
258..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=45,u0,R=(19:50,29:50),N=0,C=false,I=false,F=0,P=false,ANI=true]
266..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=46,u0,R=(1:23:11,1:33:11),N=0,C=false,I=false,F=0,P=true,ANI=true]
268..:[ComponentInfo{my.app/com.evernote.android.job.v21.PlatformJobService},jId=7,u0,R=(22:47,32:47),N=0,C=false,I=false,F=0,P=true,ANI=true]
Run Code Online (Sandbox Code Playgroud)
我在启动应用程序时只安排了4个不同的工作(在"MyApp扩展应用程序"类的实例中启动.
另外:即使我指定在重新启动之间不应该持续定期作业,重新启动后作业仍然存在.(是的,我有<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />'在我的清单中)
这是我如何安排定期工作的示例:
public static void schedulePeriodicJob() {
int jobId = new JobRequest.Builder(TSMUSyncJob.TAG_TSMU_SYNC_PERIODIC_JOB)
.setPeriodic(TimeUnit.MINUTES.toMillis(120), TimeUnit.MINUTES.toMillis(10))
//.setPersisted(true)
.build()
.schedule();
Log.i(TAG, "Persisted job …Run Code Online (Sandbox Code Playgroud) android ×9
android-architecture-components ×2
java ×2
lint ×2
android-job ×1
kotlin ×1
mvvm ×1