package com.example.emptyact
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.emptyact">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.EmptyAct">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
/**
* Automatically generated file. DO NOT MODIFY
*/
package com.example.emptyact;
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "com.example.emptyact";
public static final String BUILD_TYPE = "debug";
public static final int VERSION_CODE = 1;
public static final String VERSION_NAME = "1.0";
}
>setx /M path "%path%;C:\Users\ユーザ名\AppData\Local\Android\Sdk\platform-tools"
> adb devices
List of devices attached
0bd33489032f917a device
>adb shell screencap -p /sdcard/screen.png
>adb pull /sdcard/screen.png
/sdcard/screen.png: 1 file pulled, 0 skipped. 2.4 MB/s (44050 bytes in 0.017s)
> adb push local.file /sdcard/
> adb shell wm size
Physical size: 1080x1920
> adb shell pm list packages
>adb shell
>run-as アプリパッケージ名
>ls
cache
files
>ls files
test.lis
>cat /data/data/アプリパッケージ名/files/test.lis > /sdcard/test.lis
>exit
>adb pull /sdcard/test.lis
import android.util.Log
:
Log.d("tag","message")
import android.widget.Toast
:
protected fun showMessage(msg: String) {
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
}
:
showMessage("Hello World!")
int abc(int aaa) {
if (aaa > 0.5) return 1;
else if (aaa < -0.5) return -1;
else return 0;
}
fun abc(aaa: Int): Int {
return if (aaa > 0.5) 1 else if (aaa < -0.5) -1 else 0
}
Could not identify launch activity: Default Activity not found
Error while Launching activity
package com.example.testapp
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.RectF
import android.util.AttributeSet
import android.view.View
class CustomView : View {
constructor(cont: Context?) : super(cont) {}
constructor(cont: Context?, attr: AttributeSet?) : super(cont, attr) {}
override protected fun onDraw(c: Canvas) {
c.drawColor(Color.BLACK)
val fill_paint = Paint()
fill_paint.setStyle(Paint.Style.FILL)
fill_paint.setColor(Color.BLUE)
c.drawRect(500f, 500f, 1000f, 1000f, fill_paint)
fill_paint.setColor(Color.RED)
c.drawOval(RectF(0f, 0f, 500f, 500f), fill_paint)
}
override protected fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val widthSize = MeasureSpec.getSize(widthMeasureSpec)
val heightSize = MeasureSpec.getSize(heightMeasureSpec)
setMeasuredDimension(widthSize, heightSize)
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.04"
android:gravity="center_vertical|center_horizontal"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<com.example.testapp.CustomView
android:id="@+id/customView1"
android:layout_width="match_parent"
android:layout_height="290dp"
android:layout_weight="0.20" />
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="41dp"
android:text="Button" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testapp">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.TestApp" >
<activity
android:name=".testApp"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
package com.example.testapp
import android.os.Bundle
import android.app.Activity
class testApp : Activity() {
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
}
}
package com.example.testapp
import android.os.Bundle
import android.app.Activity
import android.widget.Toast
import android.view.View
class testApp : Activity() {
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
findViewById<View>(R.id.button1).setOnClickListener(object : View.OnClickListener {
override fun onClick(v: View?) {
Toast.makeText(this@testApp, "Hello World!", Toast.LENGTH_LONG).show()
}
})
}
}
val vvv = findViewById<View>(R.id.customView1)
val observer = vvv.getViewTreeObserver()
observer.addOnGlobalLayoutListener {
Log.d("ViewSize", "w = "+vvv.getWidth()+" h = "+vvv.getHeight())
}
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
val vvv = findViewById<View>(R.id.customView1)
Log.d("ViewSizex", "w = "+vvv.getWidth()+" h = "+vvv.getHeight())
Log.d("ViewSizem", "w = "+getMeasuredWidth()+" h = "+getMeasuredHeight())
}
override fun onSurfaceChanged(gl: GL10, width: Int, height: Int) {
GLES20.glViewport(0, 0, width, height)
Log.d("ViewSizes", "w=$width, h=$height")
}
Can't finish GitHub sharing process
Successfully created project 'プロジェクト名' on
GitHub, but initial commit failed:
Author identity unknown *** Please tell me who
you are. Run git config --global user.email
"you@example.com" git config --global
user.name "Your Name" to set your account's
default identity. Omit --global to set the identity
only in this repository. unable to auto-detect
email address (got 'ユーザ名@ノード名.(none)')
> git config --global user.email "メールアドレス"
> git config --global user.name "ユーザ名"
class MainActivity : AppCompatActivity() {
private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
// Example of a call to a native method
binding.sampleText.text = stringFromJNI() // Nativeメソッドの呼出し
}
/**
* A native method that is implemented by the 'testnative' native library,
* which is packaged with this application.
*/
external fun stringFromJNI(): String // Nativeメソッドの宣言
companion object {
// Used to load the 'testnative' library on application startup.
init {
System.loadLibrary("testnative") // C++ライブラリのロード
}
}
}
#include <jni.h>
#include <string>
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_testnative_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
char[256] hello = "Hello from C++";
return env->NewStringUTF(hello);
# buildに必要なCmakeの最小バージョン
cmake_minimum_required(VERSION 3.10.2)
# project名
project("testnative")
# buildするライブラリの定義
# ライブラリ名を指定(lib〜.so)
add_library(
testnative
# 静的リンク、動的リンクを指定
SHARED
# sourceファイル名を指定
native-lib.cpp)
# パスを設定する変数名
find_library(
log-lib
# NDKライブラリのパス
log)
# ターゲットライブラリの設定
target_link_libraries(
testnative
# includeするライブラリ
${log-lib})
android {
compileSdk 30
:
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
version '3.10.2'
}
}
:
}
include "module1";
:
int r = xxxx(10,20,30);
cmake_minimum_required(VERSION 3.10.2)
project("testnative")
add_subdirectory( module1 ) // サブディレクトリ
include_directories( ./module1/include) // インクルードするディレクトリ
add_library( testnative SHARED native-lib.cpp)
find_library( log-lib log)
target_link_libraries( testnative module1 ${log-lib}) // module1も追加する
cmake_minimum_required(VERSION 3.10.2)
include_directories( ./include)
add_library( module1 STATIC module1.c)
CMake '3.18.1' was not found in SDK, PATH, or by cmake.dir property.
EventQueue.isDispatchThread()=false Toolkit.getEventQueue()=com.intellij.ide.IdeEventQueue@7a01c3b7
:
package com.example.testapp
import android.R
import android.os.Bundle
import android.app.Activity
class testApp : Activity() {
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main))) //Unresolved reference:main
}
}
import android.R
The application is running