CS1056 Unexpected character '[]' を回避する
ASP.NET core でプロジェクトを作成し、Buildした際CS1056 が発生した
C:\Users\ユーザー名\AppData\Local\Tempのフォルダーに.NETCoreApp,Version=v2.0.AssemblyAttributes.csが 作成されているのでこれを削除し、ReBuildを行うとエラーができなくなった
IntelliJでjarを作成
Intellijでjarを作る方法がわからなかったので調べました
今回ビルドしたのはこれです!
contrib-drivers/bmx280 at master · androidthings/contrib-drivers · GitHub
File -> Project Structure
Artifacts -> Add -> JAR -> From modules with dependencies
Build -> Build Artifacts
これでビルドができます
Ubuntu環境構築
Ubuntu16.04でangularの環境構築をしました
基本的には
npm install -g @angular/cli
のみでOKです。
ただし、nodejsのバージョンが古い場合はインスールでこけてしまうようです。
nodejsのアップデートを行えば正常にインスールが完了します。
nodejsのアップデート方法は
npm install -g n n stable
で最新のnodejsがインスールできます。
Toolbarの表示
Toolbarの表示について書こうと思います。
C# - Xamarin.AndoridでToolbarの表示(88458)|teratail
質問をここに投げていましたが自己解決しました。
https://developer.xamarin.com/guides/android/user_interface/toolbar/part-1-replacing-the-action-bar/
最初はここを参考に書こうと思っていたのですが、全然動かない という状態になりました。
調べたら現在はToolbar
からandroid.support.v7.widget.Toolbar
に変更されているようです。で、このandroid.support.v7.widget.Toolbar
ですがXamarin標準では入っていないようです.
そこでNugetからXamarin.Android.Support.V7.AppCompatをインストールしてきます。 ちなみにXamarin.Android.Support.Designを入れるといろいろインストールされるの便利です(?) 入れたあとにクリーンとビルドするがおすすめ
本題
layout\Main.axml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="?attr/actionBarSize" android:background="?attr/colorPrimary" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> </LinearLayout>
values\styles.xml
<?xml version="1.0" encoding="utf-8" ?> <resources> <style name="MyTheme" parent="MyTheme.Base"> </style> <style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar"> <item name="android:windowNoTitle">true</item> <item name="windowActionBar">false</item> <item name="colorPrimary">#2196F3</item> <item name="colorPrimaryDark">#1976D2</item> <item name="colorAccent">#FF4081</item> </style> </resources>
values-v21\stles.xml
<?xml version="1.0" encoding="utf-8" ?> <resources> <style name="MyTheme" parent="MyTheme.Base"> <item name="android:windowContentTransitions">true</item> <item name="android:windowAllowEnterTransitionOverlap">true</item> <item name="android:windowAllowReturnTransitionOverlap">true</item> <item name="android:windowSharedElementEnterTransition">@android:transition/move</item> <item name="android:windowSharedElementExitTransition">@android:transition/move</item> </style> </resources>
MainActivity.cs
using Android.App; using Android.OS; using Android.Support.V7.App; using Toolbar = Android.Support.V7.Widget.Toolbar; namespace App2.Droid { [Activity (Label = "App2.Android", MainLauncher = true, Icon = "@drawable/icon")] public class MainActivity : AppCompatActivity { protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); Toolbar toolbar = FindViewById<Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); SupportActionBar.Title = "My Toolbar"; } } }
これだけで動きそう…
Unhandled Exception: Java.Lang.IllegalArgumentException: AppCompat does not support the current theme features: { windowActionBar: false, windowActionBarOverlay: false, android:windowIsFloating: false, windowActionModeOverlay: false, windowNoTitle: false } occurred
残念でした.デプロイ時SetContentView
で例外が発生して動かない
対策
Androidのトレーニングサイト(https://developer.android.com/training/appbar/setting-up.html)に次のように書かれていました
<application android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
これをAndroidManifestに書けば動く!? ビルド時にエラーが出ましたね
Working with AndroidManifest.xml - Xamarin
ここを見るとapplicationタグはAssemblyInfoに書けばいいみたいです。
[assembly: Application(Theme = "@style/Theme.AppCompat.Light.NoActionBar")]
今回苦しんだ点
Andoridの知識のなさが今回一番苦しみました。もっとAndoridと仲良くなるためにもう1台端末がほしいな()
あとXamarini.Androidが更新されていないというにも苦しみましたね。
今後どんどんXamarin.Andoirdについて書いて行こうと思います
The "ResolveLibraryProjectImports" task failed unexpectedly.が発生する
Android Support Design Libraryを入れたら
エラーが発生するように…
Severity Code Description Project File Line Suppression State Error The "ResolveLibraryProjectImports" task failed unexpectedly. System.IO.PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters. at System.IO.PathHelper.GetFullPathName() at System.IO.Path.LegacyNormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths) at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths) at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at Xamarin.Tools.Zip.ZipEntry.DoExtract(IntPtr zipFile, String destinationPath, FileMode outputFileMode, EntryExtractEventArgs args) at Xamarin.Tools.Zip.ZipEntry.Extract(String destinationDir, String destinationFileName, FileMode outputFileMode) at Xamarin.Android.Tools.Files.ExtractAll(ZipArchive zip, String destination, Action`2 progressCallback) at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Extract(DirectoryAssemblyResolver res, ICollection`1 jars, ICollection`1 resolvedResourceDirectories, ICollection`1 resolvedAssetDirectories, ICollection`1 resolvedEnvironments) at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Execute() at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() tmplate_android.Android
つらみしかないと思いつつエラーを見るとパスが長いと言われてますね
現在プロジェクトが以下の場所においています
C:\Users\user_name\Documents\Visual Studio 2017\Projects\tmplate_android
これを G:\project\tmplate_android
(今回はGドライブ直下に置きましたがCドライブ直下でもOKです)
に置くとエラーが出なくなりました
ListView
ListView
Mian.axmlでListViewの定義をします。 そのあと表示させるViewのテンプレートを作成しました。
Main.axml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/listView" android:layout_height="match_parent" android:layout_width="wrap_content" /> </LinearLayout>
ViewTmplate
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/textItem" android:textSize="30sp" android:layout_width="match_parent" android:layout_height="match_parent" />
ListViewにlistを渡すためにArrayAdapterを使います。
MainActivity.cs
using System; using Android.App; using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS; namespace App3_native.Droid { [Activity (Label = "App3_native.Android", MainLauncher = true, Icon = "@drawable/icon")] public class MainActivity : Activity { ListView listView; ArrayAdapter adapter; protected override void OnCreate (Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Main); listView = FindViewById<ListView>(Resource.Id.listView); var items = new string[] { "List1", "List2", "List3", "List4" }; adapter = new ArrayAdapter<string>(this, Resource.Layout.ViewTmplate, items); listView.Adapter = adapter; listView.ItemClick += OnListItemClick; } private void OnListItemClick(object sender, AdapterView.ItemClickEventArgs e) { var listView = sender as ListView; var t = adapter.GetItem(e.Position).ToString(); Toast.MakeText(this, t, ToastLength.Short).Show(); } } }
画面遷移
こんな感じで画面遷移ができる 画面遷移先のActitityを用意しておくことが大切
using System; using Android.App; using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS; namespace App_naitive.Droid { [Activity (Label = "App_naitive.Android", MainLauncher = true, Icon = "@drawable/icon")] public class MainActivity : Activity { protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); Button btn = FindViewById<Button>(Resource.Id.button1); EditText eText = FindViewById<EditText>(Resource.Id.editText1); btn.Click += (sender, e) => { var intent = new Intent(this, typeof(Page2)); intent.SetData(Android.Net.Uri.Parse(eText.Text)); StartActivity(intent); }; Button btn2 = FindViewById<Button>(Resource.Id.button2); btn2.Click += (sender, e) => { var dialog = new AlertDialog.Builder(this); dialog.SetMessage("dialog:" + eText.Text); dialog.SetNeutralButton("dialog", delegate { var intent = new Intent(Intent.ActionCall); intent.SetData(Android.Net.Uri.Parse(eText.Text)); StartActivity(intent); }); dialog.SetNegativeButton("cancel", delegate { }); dialog.Show(); }; } } }