【问题标题】:Hybrid Mobile App with Angular and Android Studio使用 Angular 和 Android Studio 的混合移动应用程序
【发布时间】:2018-11-16 10:18:14
【问题描述】:

我正处于危机之中。我是 Angular 的新手,甚至是 Android Studio 的新手,并且已经拍摄了我所有的资源来试图解决这个问题,如果这是显而易见的事情,我很抱歉......

问题:为什么当我尝试通过 Android Studio 启动我的 Angular 应用程序时,会收到 404 错误。

说明: 目标是通过 android studio 将我的 angular web 应用程序包装在 webview 中,使其成为混合应用程序,从而将我的 angular web 应用程序启动到 playstore ......我正在关注这个 web 教程任务...
https://www.youtube.com/watch?v=a5dlmqM9Oo8
如果我测试像谷歌这样的网站地址,这可以工作,但如果我尝试我的 Angular 应用程序地址,屏幕保持空白或返回 404“在此服务器上找不到请求的 URL”。我已经在个人服务器上启动了我的 Angular 应用程序,它可以通过我的浏览器完美运行。
我的猜测是,角度路由会阻止 webview 加载应用程序...我已经尝试了以下修复,没有任何更改...

1) 哈希 How to use the HashLocationStrategy with the Auth0 Lock widget for user login

    @NgModule({
      imports: [RouterModule.forRoot(routes,{useHash: true})], ...

2) Apache 服务器中的 .htaccess
https://angular.io/guide/deployment#development-servers

    RewriteEngine On
       # If an existing asset or directory is requested go to it as it is
       RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
       RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
       RewriteRule ^ - [L]
       # If the requested resource doesn't exist, use index.html
    RewriteRule ^ /index.html


如果您需要更多代码,请告诉我。我不确定这是否可能,但如果不是,我将不得不学习 Ionic 或找出其他东西。感谢stackoverflow

【问题讨论】:

    标签: android angular android-studio


    【解决方案1】:

    我真的希望这可以帮助有需要的人。我认为部分问题是这个 Angular 移动应用程序为 JWT 使用 localstorage 并且有一些用于数据库的 API...
    无论如何,修复来自 Android Studio

        public class MainActivity extends AppCompatActivity {
           private WebView myWebView;
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                myWebView = (WebView)findViewById(R.id.web1);
                WebSettings webSettings = myWebView.getSettings();
                webSettings.setJavaScriptEnabled(true);
           // THE FIX WAS THESE TWO LINES BELOW //
                myWebView.getSettings().setAppCacheEnabled(true);
                myWebView.getSettings().setDomStorageEnabled(true);
    
                myWebView.loadUrl("MYANGULARAPPWEBSITE");
                myWebView.setWebViewClient(new WebViewClient());
    
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-01
      • 2016-03-17
      • 2015-01-06
      • 1970-01-01
      • 1970-01-01
      • 2018-06-10
      • 1970-01-01
      相关资源
      最近更新 更多